3 month roland feedback timeout:
- Pass lint - knf - convert ints to size_t's
This commit is contained in:
parent
8531d31a58
commit
ad18d2e41e
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cgdconfig.c,v 1.18 2007/02/06 14:04:01 cbiere Exp $ */
|
||||
/* $NetBSD: cgdconfig.c,v 1.19 2007/11/06 02:50:48 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -41,7 +41,7 @@
|
||||
__COPYRIGHT(
|
||||
"@(#) Copyright (c) 2002, 2003\
|
||||
The NetBSD Foundation, Inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: cgdconfig.c,v 1.18 2007/02/06 14:04:01 cbiere Exp $");
|
||||
__RCSID("$NetBSD: cgdconfig.c,v 1.19 2007/11/06 02:50:48 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
@ -100,10 +100,10 @@ static int do_all(const char *, int, char **,
|
||||
static int configure_params(int, const char *, const char *,
|
||||
struct params *);
|
||||
static void eliminate_cores(void);
|
||||
static bits_t *getkey(const char *, struct keygen *, int);
|
||||
static bits_t *getkey_storedkey(const char *, struct keygen *, int);
|
||||
static bits_t *getkey_randomkey(const char *, struct keygen *, int, int);
|
||||
static bits_t *getkey_pkcs5_pbkdf2(const char *, struct keygen *, int, int);
|
||||
static bits_t *getkey(const char *, struct keygen *, size_t);
|
||||
static bits_t *getkey_storedkey(const char *, struct keygen *, size_t);
|
||||
static bits_t *getkey_randomkey(const char *, struct keygen *, size_t, int);
|
||||
static bits_t *getkey_pkcs5_pbkdf2(const char *, struct keygen *, size_t, int);
|
||||
static int opendisk_werror(const char *, char *, size_t);
|
||||
static int unconfigure_fd(int);
|
||||
static int verify(struct params *, int);
|
||||
@ -117,28 +117,28 @@ static void usage(void);
|
||||
unsigned verbose = 0;
|
||||
|
||||
#define VERBOSE(x,y) if (verbose >= x) y
|
||||
#define VPRINTF(x,y) if (verbose >= x) printf y
|
||||
#define VPRINTF(x,y) if (verbose >= x) (void)printf y
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
fprintf(stderr, "usage: %s [-nv] [-V vmeth] cgd dev [paramsfile]\n",
|
||||
(void)fprintf(stderr, "usage: %s [-nv] [-V vmeth] cgd dev [paramsfile]\n",
|
||||
getprogname());
|
||||
fprintf(stderr, " %s -C [-nv] [-f configfile]\n", getprogname());
|
||||
fprintf(stderr, " %s -U [-nv] [-f configfile]\n", getprogname());
|
||||
fprintf(stderr, " %s -G [-nv] [-i ivmeth] [-k kgmeth] "
|
||||
(void)fprintf(stderr, " %s -C [-nv] [-f configfile]\n", getprogname());
|
||||
(void)fprintf(stderr, " %s -U [-nv] [-f configfile]\n", getprogname());
|
||||
(void)fprintf(stderr, " %s -G [-nv] [-i ivmeth] [-k kgmeth] "
|
||||
"[-o outfile] paramsfile\n", getprogname());
|
||||
fprintf(stderr, " %s -g [-nv] [-i ivmeth] [-k kgmeth] "
|
||||
(void)fprintf(stderr, " %s -g [-nv] [-i ivmeth] [-k kgmeth] "
|
||||
"[-o outfile] alg [keylen]\n", getprogname());
|
||||
fprintf(stderr, " %s -s [-nv] [-i ivmeth] cgd dev alg "
|
||||
(void)fprintf(stderr, " %s -s [-nv] [-i ivmeth] cgd dev alg "
|
||||
"[keylen]\n", getprogname());
|
||||
fprintf(stderr, " %s -u [-nv] cgd\n", getprogname());
|
||||
(void)fprintf(stderr, " %s -u [-nv] cgd\n", getprogname());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int
|
||||
parse_int(const char *s)
|
||||
parse_size_t(const char *s, size_t *l)
|
||||
{
|
||||
char *endptr;
|
||||
long v;
|
||||
@ -155,7 +155,8 @@ parse_int(const char *s)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return v;
|
||||
*l = (size_t)v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -203,10 +204,9 @@ main(int argc, char **argv)
|
||||
break;
|
||||
case 'b':
|
||||
{
|
||||
int size;
|
||||
size_t size;
|
||||
|
||||
size = parse_int(optarg);
|
||||
if (size == -1 && errno)
|
||||
if (parse_size_t(optarg, &size) == -1)
|
||||
usage();
|
||||
tp = params_bsize(size);
|
||||
if (!tp)
|
||||
@ -281,18 +281,19 @@ main(int argc, char **argv)
|
||||
return do_all(cfile, argc, argv, unconfigure);
|
||||
case ACTION_CONFIGSTDIN:
|
||||
return configure_stdin(p, argc, argv);
|
||||
default:
|
||||
errx(EXIT_FAILURE, "undefined action");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
errx(EXIT_FAILURE, "undefined action");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static bits_t *
|
||||
getkey(const char *dev, struct keygen *kg, int len)
|
||||
getkey(const char *dev, struct keygen *kg, size_t len)
|
||||
{
|
||||
bits_t *ret = NULL;
|
||||
bits_t *tmp;
|
||||
|
||||
VPRINTF(3, ("getkey(\"%s\", %p, %d) called\n", dev, kg, len));
|
||||
VPRINTF(3, ("getkey(\"%s\", %p, %zu) called\n", dev, kg, len));
|
||||
for (; kg; kg=kg->next) {
|
||||
switch (kg->kg_method) {
|
||||
case KEYGEN_STOREDKEY:
|
||||
@ -330,21 +331,15 @@ getkey(const char *dev, struct keygen *kg, int len)
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bits_t *
|
||||
getkey_storedkey(const char *target, struct keygen *kg, int keylen)
|
||||
getkey_storedkey(const char *target, struct keygen *kg, size_t keylen)
|
||||
{
|
||||
|
||||
(void) target;
|
||||
(void) keylen;
|
||||
return bits_dup(kg->kg_key);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bits_t *
|
||||
getkey_randomkey(const char *target, struct keygen *kg, int keylen, int hard)
|
||||
getkey_randomkey(const char *target, struct keygen *kg, size_t keylen, int hard)
|
||||
{
|
||||
|
||||
(void) target;
|
||||
(void) kg;
|
||||
return bits_getrandombits(keylen, hard);
|
||||
}
|
||||
|
||||
@ -358,15 +353,16 @@ getkey_randomkey(const char *target, struct keygen *kg, int keylen, int hard)
|
||||
* be the compat argument.
|
||||
*/
|
||||
static bits_t *
|
||||
getkey_pkcs5_pbkdf2(const char *target, struct keygen *kg, int keylen, int compat)
|
||||
getkey_pkcs5_pbkdf2(const char *target, struct keygen *kg, size_t keylen,
|
||||
int compat)
|
||||
{
|
||||
bits_t *ret;
|
||||
char *passp;
|
||||
const u_int8_t *passp;
|
||||
char buf[1024];
|
||||
u_int8_t *tmp;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s's passphrase:", target);
|
||||
passp = getpass(buf);
|
||||
passp = (const u_int8_t *)(void *)getpass(buf);
|
||||
if (pkcs5_pbkdf2(&tmp, BITS2BYTES(keylen), passp, strlen(passp),
|
||||
bits_getbuf(kg->kg_salt), BITS2BYTES(bits_len(kg->kg_salt)),
|
||||
kg->kg_iterations, compat)) {
|
||||
@ -388,8 +384,6 @@ unconfigure(int argc, char **argv, struct params *inparams, int flags)
|
||||
int ret;
|
||||
char buf[MAXPATHLEN] = "";
|
||||
|
||||
(void) inparams;
|
||||
|
||||
/* only complain about additional arguments, if called from main() */
|
||||
if (flags == CONFIG_FLAGS_FROMMAIN && argc != 1)
|
||||
usage();
|
||||
@ -415,7 +409,7 @@ unconfigure(int argc, char **argv, struct params *inparams, int flags)
|
||||
return 0;
|
||||
|
||||
ret = unconfigure_fd(fd);
|
||||
close(fd);
|
||||
(void)close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -512,16 +506,16 @@ configure(int argc, char **argv, struct params *inparams, int flags)
|
||||
|
||||
warnx("verification failed, please reenter passphrase");
|
||||
|
||||
unconfigure_fd(fd);
|
||||
close(fd);
|
||||
(void)unconfigure_fd(fd);
|
||||
(void)close(fd);
|
||||
}
|
||||
|
||||
params_free(p);
|
||||
close(fd);
|
||||
(void)close(fd);
|
||||
return 0;
|
||||
bail_err:
|
||||
params_free(p);
|
||||
close(fd);
|
||||
(void)close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -537,10 +531,9 @@ configure_stdin(struct params *p, int argc, char **argv)
|
||||
|
||||
p->algorithm = string_fromcharstar(argv[2]);
|
||||
if (argc > 3) {
|
||||
int keylen;
|
||||
size_t keylen;
|
||||
|
||||
keylen = parse_int(argv[3]);
|
||||
if (keylen == -1 && errno) {
|
||||
if (parse_size_t(argv[3], &keylen) == -1) {
|
||||
warn("failed to parse key length");
|
||||
return -1;
|
||||
}
|
||||
@ -597,7 +590,7 @@ configure_params(int fd, const char *cgd, const char *dev, struct params *p)
|
||||
if (!cgd || !dev)
|
||||
return -1;
|
||||
|
||||
memset(&ci, 0x0, sizeof(ci));
|
||||
(void)memset(&ci, 0x0, sizeof(ci));
|
||||
ci.ci_disk = dev;
|
||||
ci.ci_alg = string_tocharstar(p->algorithm);
|
||||
ci.ci_ivmethod = string_tocharstar(p->ivmeth);
|
||||
@ -679,23 +672,24 @@ static off_t sblock_try[] = SBLOCKSEARCH;
|
||||
static int
|
||||
verify_ffs(int fd)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; sblock_try[i] != -1; i++) {
|
||||
char buf[SBLOCKSIZE];
|
||||
struct fs fs;
|
||||
union {
|
||||
char buf[SBLOCKSIZE];
|
||||
struct fs fs;
|
||||
} u;
|
||||
ssize_t ret;
|
||||
|
||||
ret = pread(fd, buf, sizeof(buf), sblock_try[i]);
|
||||
ret = pread(fd, &u, sizeof(u), sblock_try[i]);
|
||||
if (ret < 0) {
|
||||
warn("pread");
|
||||
break;
|
||||
} else if ((size_t)ret < sizeof(fs)) {
|
||||
} else if ((size_t)ret < sizeof(u)) {
|
||||
warnx("pread: incomplete block");
|
||||
break;
|
||||
}
|
||||
memcpy(&fs, buf, sizeof(fs));
|
||||
switch (fs.fs_magic) {
|
||||
switch (u.fs.fs_magic) {
|
||||
case FS_UFS1_MAGIC:
|
||||
case FS_UFS2_MAGIC:
|
||||
case FS_UFS1_MAGIC_SWAPPED:
|
||||
@ -748,10 +742,9 @@ generate(struct params *p, int argc, char **argv, const char *outfile)
|
||||
|
||||
p->algorithm = string_fromcharstar(argv[0]);
|
||||
if (argc > 1) {
|
||||
int keylen;
|
||||
size_t keylen;
|
||||
|
||||
keylen = parse_int(argv[1]);
|
||||
if (keylen == -1 && errno) {
|
||||
if (parse_size_t(argv[1], &keylen) == -1) {
|
||||
warn("Failed to parse key length");
|
||||
return -1;
|
||||
}
|
||||
@ -828,8 +821,8 @@ generate_convert(struct params *p, int argc, char **argv, const char *outfile)
|
||||
if (!p->keygen)
|
||||
return -1;
|
||||
}
|
||||
params_filldefaults(p);
|
||||
keygen_filldefaults(p->keygen, p->keylen);
|
||||
(void)params_filldefaults(p);
|
||||
(void)keygen_filldefaults(p->keygen, p->keylen);
|
||||
p->key = getkey("new file", p->keygen, p->keylen);
|
||||
|
||||
kg = keygen_generate(KEYGEN_STOREDKEY);
|
||||
@ -848,6 +841,7 @@ bail:
|
||||
}
|
||||
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
do_all(const char *cfile, int argc, char **argv,
|
||||
int (*conf)(int, char **, struct params *, int))
|
||||
{
|
||||
@ -860,7 +854,6 @@ do_all(const char *cfile, int argc, char **argv,
|
||||
char *line;
|
||||
char **my_argv;
|
||||
|
||||
(void) argv;
|
||||
if (argc > 0)
|
||||
usage();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: params.c,v 1.19 2007/02/06 01:55:40 cbiere Exp $ */
|
||||
/* $NetBSD: params.c,v 1.20 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: params.c,v 1.19 2007/02/06 01:55:40 cbiere Exp $");
|
||||
__RCSID("$NetBSD: params.c,v 1.20 2007/11/06 02:50:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -59,7 +59,7 @@ static void params_init(struct params *);
|
||||
|
||||
static void print_kvpair_cstr(FILE *, int, const char *, const char *);
|
||||
static void print_kvpair_string(FILE *, int, const char *, const string_t *);
|
||||
static void print_kvpair_int(FILE *, int, const char *, int);
|
||||
static void print_kvpair_int(FILE *, int, const char *, size_t);
|
||||
static void print_kvpair_b64(FILE *, int, int, const char *, bits_t *);
|
||||
|
||||
static void spaces(FILE *, int);
|
||||
@ -97,8 +97,8 @@ params_init(struct params *p)
|
||||
p->algorithm = NULL;
|
||||
p->ivmeth = NULL;
|
||||
p->key = NULL;
|
||||
p->keylen = -1;
|
||||
p->bsize = -1;
|
||||
p->keylen = (size_t)-1;
|
||||
p->bsize = (size_t)-1;
|
||||
p->verify_method = VERIFY_UNKNOWN;
|
||||
p->dep_keygen = NULL;
|
||||
p->keygen = NULL;
|
||||
@ -133,9 +133,9 @@ params_combine(struct params *p1, struct params *p2)
|
||||
string_assign(&p->algorithm, p2->algorithm);
|
||||
if (p2->ivmeth)
|
||||
string_assign(&p->ivmeth, p2->ivmeth);
|
||||
if (p2->keylen != -1)
|
||||
if (p2->keylen != (size_t)-1)
|
||||
p->keylen = p2->keylen;
|
||||
if (p2->bsize != -1)
|
||||
if (p2->bsize != (size_t)-1)
|
||||
p->bsize = p2->bsize;
|
||||
if (p2->verify_method != VERIFY_UNKNOWN)
|
||||
p->verify_method = p2->verify_method;
|
||||
@ -154,15 +154,15 @@ params_combine(struct params *p1, struct params *p2)
|
||||
int
|
||||
params_filldefaults(struct params *p)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (p->verify_method == VERIFY_UNKNOWN)
|
||||
p->verify_method = VERIFY_NONE;
|
||||
if (!p->ivmeth)
|
||||
p->ivmeth = string_fromcharstar("encblkno");
|
||||
if (p->keylen == -1) {
|
||||
if (p->keylen == (size_t)-1) {
|
||||
i = crypt_defaults_lookup(string_tocharstar(p->algorithm));
|
||||
if (i != -1) {
|
||||
if (i != (size_t)-1) {
|
||||
p->keylen = crypto_defaults[i].keylen;
|
||||
} else {
|
||||
warnx("could not determine key length for unknown "
|
||||
@ -206,7 +206,7 @@ params_verify(const struct params *p)
|
||||
if (strcmp("encblkno", string_tocharstar(p->ivmeth)))
|
||||
warnx("unknown IV method \"%s\" (warning)",
|
||||
string_tocharstar(p->ivmeth));
|
||||
if (p->keylen == -1) {
|
||||
if (p->keylen == (size_t)-1) {
|
||||
warnx("unspecified key length");
|
||||
return 0;
|
||||
}
|
||||
@ -233,7 +233,7 @@ params_ivmeth(string_t *in)
|
||||
}
|
||||
|
||||
struct params *
|
||||
params_keylen(int in)
|
||||
params_keylen(size_t in)
|
||||
{
|
||||
struct params *p = params_new();
|
||||
|
||||
@ -242,7 +242,7 @@ params_keylen(int in)
|
||||
}
|
||||
|
||||
struct params *
|
||||
params_bsize(int in)
|
||||
params_bsize(size_t in)
|
||||
{
|
||||
struct params *p = params_new();
|
||||
|
||||
@ -298,7 +298,7 @@ keygen_new(void)
|
||||
|
||||
kg = emalloc(sizeof(*kg));
|
||||
kg->kg_method = KEYGEN_UNKNOWN;
|
||||
kg->kg_iterations = -1;
|
||||
kg->kg_iterations = (size_t)-1;
|
||||
kg->kg_salt = NULL;
|
||||
kg->kg_key = NULL;
|
||||
kg->next = NULL;
|
||||
@ -330,7 +330,7 @@ keygen_verify(const struct keygen *kg)
|
||||
return 1;
|
||||
switch (kg->kg_method) {
|
||||
case KEYGEN_PKCS5_PBKDF2_OLD:
|
||||
if (kg->kg_iterations == -1) {
|
||||
if (kg->kg_iterations == (size_t)-1) {
|
||||
warnx("keygen pkcs5_pbkdf2 must provide `iterations'");
|
||||
return 0;
|
||||
}
|
||||
@ -342,7 +342,7 @@ keygen_verify(const struct keygen *kg)
|
||||
}
|
||||
break;
|
||||
case KEYGEN_PKCS5_PBKDF2_SHA1:
|
||||
if (kg->kg_iterations == -1) {
|
||||
if (kg->kg_iterations == (size_t)-1) {
|
||||
warnx("keygen pkcs5_pbkdf2/sha1 must provide `iterations'");
|
||||
return 0;
|
||||
}
|
||||
@ -354,7 +354,7 @@ keygen_verify(const struct keygen *kg)
|
||||
}
|
||||
break;
|
||||
case KEYGEN_STOREDKEY:
|
||||
if (kg->kg_iterations != -1)
|
||||
if (kg->kg_iterations != (size_t)-1)
|
||||
warnx("keygen storedkey does not need `iterations'");
|
||||
if (!kg->kg_key) {
|
||||
warnx("keygen storedkey must provide a key");
|
||||
@ -365,7 +365,7 @@ keygen_verify(const struct keygen *kg)
|
||||
break;
|
||||
case KEYGEN_RANDOMKEY:
|
||||
case KEYGEN_URANDOMKEY:
|
||||
if (kg->kg_iterations != -1)
|
||||
if (kg->kg_iterations != (size_t)-1)
|
||||
warnx("keygen [u]randomkey does not need `iterations'");
|
||||
if (kg->kg_key)
|
||||
warnx("keygen [u]randomkey does not need `key'");
|
||||
@ -398,7 +398,7 @@ keygen_generate(int method)
|
||||
*/
|
||||
|
||||
int
|
||||
keygen_filldefaults(struct keygen *kg, int keylen)
|
||||
keygen_filldefaults(struct keygen *kg, size_t keylen)
|
||||
{
|
||||
|
||||
if (!kg)
|
||||
@ -500,7 +500,7 @@ keygen_salt(bits_t *in)
|
||||
}
|
||||
|
||||
struct keygen *
|
||||
keygen_iterations(int in)
|
||||
keygen_iterations(size_t in)
|
||||
{
|
||||
struct keygen *kg = keygen_new();
|
||||
|
||||
@ -552,7 +552,7 @@ params_fget(FILE *f)
|
||||
*/
|
||||
|
||||
if (p->dep_keygen) {
|
||||
if (p->dep_keygen->kg_iterations == -1)
|
||||
if (p->dep_keygen->kg_iterations == (size_t)-1)
|
||||
p->dep_keygen->kg_iterations = 128;
|
||||
p->dep_keygen->next = p->keygen;
|
||||
if (p->dep_keygen->kg_key) {
|
||||
@ -579,7 +579,7 @@ params_cget(const char *fn)
|
||||
return NULL;
|
||||
}
|
||||
p = params_fget(f);
|
||||
fclose(f);
|
||||
(void)fclose(f);
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -591,7 +591,7 @@ spaces(FILE *f, int len)
|
||||
{
|
||||
|
||||
while (len-- > 0)
|
||||
fputc(' ', f);
|
||||
(void)fputc(' ', f);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -599,7 +599,7 @@ print_kvpair_cstr(FILE *f, int ts, const char *key, const char *val)
|
||||
{
|
||||
|
||||
spaces(f, ts);
|
||||
fprintf(f, "%s %s;\n", key, val);
|
||||
(void)fprintf(f, "%s %s;\n", key, val);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -610,14 +610,14 @@ print_kvpair_string(FILE *f, int ts, const char *key, const string_t *val)
|
||||
}
|
||||
|
||||
static void
|
||||
print_kvpair_int(FILE *f, int ts, const char *key, int val)
|
||||
print_kvpair_int(FILE *f, int ts, const char *key, size_t val)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
if (!key || val == -1)
|
||||
if (!key || val == (size_t)-1)
|
||||
return;
|
||||
|
||||
if (asprintf(&tmp, "%d", val) == -1)
|
||||
if (asprintf(&tmp, "%zu", val) == -1)
|
||||
err(1, NULL);
|
||||
print_kvpair_cstr(f, ts, key, tmp);
|
||||
free(tmp);
|
||||
@ -646,19 +646,19 @@ print_kvpair_b64(FILE *f, int curpos, int ts, const char *key, bits_t *val)
|
||||
len = strlen(out);
|
||||
|
||||
spaces(f, ts);
|
||||
fprintf(f, "%s ", key);
|
||||
(void)fprintf(f, "%s ", key);
|
||||
curpos += ts + strlen(key) + 1;
|
||||
ts = curpos;
|
||||
|
||||
for (i=0, pos=curpos; i < len; i++, pos++) {
|
||||
if (pos > WRAP_COL) {
|
||||
fprintf(f, " \\\n");
|
||||
(void)fprintf(f, " \\\n");
|
||||
spaces(f, ts);
|
||||
pos = ts;
|
||||
}
|
||||
fputc(out[i], f);
|
||||
(void)fputc(out[i], f);
|
||||
}
|
||||
fprintf(f, ";\n");
|
||||
(void)fprintf(f, ";\n");
|
||||
string_free(str);
|
||||
}
|
||||
|
||||
@ -669,31 +669,31 @@ keygen_fput(struct keygen *kg, int ts, FILE *f)
|
||||
|
||||
if (!kg)
|
||||
return 0;
|
||||
fprintf(f, "keygen ");
|
||||
(void)fprintf(f, "keygen ");
|
||||
curpos += strlen("keygen ");
|
||||
switch (kg->kg_method) {
|
||||
case KEYGEN_STOREDKEY:
|
||||
fprintf(f, "storedkey ");
|
||||
(void)fprintf(f, "storedkey ");
|
||||
curpos += strlen("storedkey ");
|
||||
print_kvpair_b64(f, curpos, 0, "key", kg->kg_key);
|
||||
break;
|
||||
case KEYGEN_RANDOMKEY:
|
||||
fprintf(f, "randomkey;\n");
|
||||
(void)fprintf(f, "randomkey;\n");
|
||||
break;
|
||||
case KEYGEN_URANDOMKEY:
|
||||
fprintf(f, "urandomkey;\n");
|
||||
(void)fprintf(f, "urandomkey;\n");
|
||||
break;
|
||||
case KEYGEN_PKCS5_PBKDF2_OLD:
|
||||
fprintf(f, "pkcs5_pbkdf2 {\n");
|
||||
(void)fprintf(f, "pkcs5_pbkdf2 {\n");
|
||||
print_kvpair_int(f, ts, "iterations", kg->kg_iterations);
|
||||
print_kvpair_b64(f, 0, ts, "salt", kg->kg_salt);
|
||||
fprintf(f, "};\n");
|
||||
(void)fprintf(f, "};\n");
|
||||
break;
|
||||
case KEYGEN_PKCS5_PBKDF2_SHA1:
|
||||
fprintf(f, "pkcs5_pbkdf2/sha1 {\n");
|
||||
(void)fprintf(f, "pkcs5_pbkdf2/sha1 {\n");
|
||||
print_kvpair_int(f, ts, "iterations", kg->kg_iterations);
|
||||
print_kvpair_b64(f, 0, ts, "salt", kg->kg_salt);
|
||||
fprintf(f, "};\n");
|
||||
(void)fprintf(f, "};\n");
|
||||
break;
|
||||
default:
|
||||
warnx("keygen_fput: %d not a valid method", kg->kg_method);
|
||||
@ -728,8 +728,7 @@ params_fput(struct params *p, FILE *f)
|
||||
warnx("unsupported verify_method (%d)", p->verify_method);
|
||||
return -1;
|
||||
}
|
||||
keygen_fput(p->keygen, TAB_COL, f);
|
||||
return 0;
|
||||
return keygen_fput(p->keygen, TAB_COL, f);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: params.h,v 1.7 2004/08/13 15:03:57 tv Exp $ */
|
||||
/* $NetBSD: params.h,v 1.8 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -43,7 +43,7 @@
|
||||
|
||||
struct keygen {
|
||||
int kg_method;
|
||||
int kg_iterations;
|
||||
size_t kg_iterations;
|
||||
bits_t *kg_salt;
|
||||
bits_t *kg_key;
|
||||
struct keygen *next;
|
||||
@ -53,8 +53,8 @@ struct params {
|
||||
string_t *algorithm;
|
||||
string_t *ivmeth;
|
||||
bits_t *key;
|
||||
int keylen;
|
||||
int bsize;
|
||||
size_t keylen;
|
||||
size_t bsize;
|
||||
int verify_method;
|
||||
struct keygen *dep_keygen;
|
||||
struct keygen *keygen;
|
||||
@ -87,8 +87,8 @@ int params_verify(const struct params *);
|
||||
struct params *params_combine(struct params *, struct params *);
|
||||
struct params *params_algorithm(string_t *);
|
||||
struct params *params_ivmeth(string_t *);
|
||||
struct params *params_keylen(int);
|
||||
struct params *params_bsize(int);
|
||||
struct params *params_keylen(size_t);
|
||||
struct params *params_bsize(size_t);
|
||||
struct params *params_verify_method(string_t *);
|
||||
struct params *params_keygen(struct keygen *);
|
||||
struct params *params_dep_keygen(struct keygen *);
|
||||
@ -101,7 +101,7 @@ int params_cput(struct params *, const char *);
|
||||
struct keygen *keygen_new(void);
|
||||
void keygen_free(struct keygen *);
|
||||
|
||||
int keygen_filldefaults(struct keygen *, int);
|
||||
int keygen_filldefaults(struct keygen *, size_t);
|
||||
int keygen_verify(const struct keygen *);
|
||||
void keygen_addlist(struct keygen **, struct keygen *);
|
||||
|
||||
@ -110,7 +110,7 @@ struct keygen *keygen_generate(int);
|
||||
struct keygen *keygen_method(string_t *);
|
||||
struct keygen *keygen_set_method(struct keygen *, string_t *);
|
||||
struct keygen *keygen_salt(bits_t *);
|
||||
struct keygen *keygen_iterations(int);
|
||||
struct keygen *keygen_iterations(size_t);
|
||||
struct keygen *keygen_key(bits_t *);
|
||||
|
||||
int keygen_fput(struct keygen *, int, FILE *);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pkcs5_pbkdf2.c,v 1.10 2007/01/27 08:29:14 cbiere Exp $ */
|
||||
/* $NetBSD: pkcs5_pbkdf2.c,v 1.11 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -53,7 +53,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: pkcs5_pbkdf2.c,v 1.10 2007/01/27 08:29:14 cbiere Exp $");
|
||||
__RCSID("$NetBSD: pkcs5_pbkdf2.c,v 1.11 2007/11/06 02:50:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/resource.h>
|
||||
@ -70,39 +70,39 @@ __RCSID("$NetBSD: pkcs5_pbkdf2.c,v 1.10 2007/01/27 08:29:14 cbiere Exp $");
|
||||
#include "pkcs5_pbkdf2.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void prf_iterate(u_int8_t *, const u_int8_t *, int,
|
||||
const u_int8_t *, int, int, int);
|
||||
static int pkcs5_pbkdf2_time(int, int);
|
||||
static void prf_iterate(u_int8_t *, const u_int8_t *, size_t,
|
||||
const u_int8_t *, size_t, size_t, size_t);
|
||||
static int pkcs5_pbkdf2_time(size_t, size_t);
|
||||
|
||||
#define PRF_BLOCKLEN 20
|
||||
|
||||
static void
|
||||
prf_iterate(u_int8_t *r, const u_int8_t *P, int Plen,
|
||||
const u_int8_t *S, int Slen, int c, int ind)
|
||||
prf_iterate(u_int8_t *r, const u_int8_t *P, size_t Plen,
|
||||
const u_int8_t *S, size_t Slen, size_t c, size_t ind)
|
||||
{
|
||||
int first_time = 1;
|
||||
int i;
|
||||
int datalen;
|
||||
u_int tmplen;
|
||||
size_t i;
|
||||
size_t datalen;
|
||||
size_t tmplen;
|
||||
u_int8_t *data;
|
||||
u_int8_t tmp[EVP_MAX_MD_SIZE];
|
||||
|
||||
data = emalloc(Slen + 4);
|
||||
memcpy(data, S, Slen);
|
||||
(void)memcpy(data, S, Slen);
|
||||
be32enc(data + Slen, ind);
|
||||
datalen = Slen + 4;
|
||||
|
||||
for (i=0; i < c; i++) {
|
||||
HMAC(EVP_sha1(), P, Plen, data, datalen, tmp, &tmplen);
|
||||
(void)HMAC(EVP_sha1(), P, Plen, data, datalen, tmp, &tmplen);
|
||||
|
||||
assert(tmplen == PRF_BLOCKLEN);
|
||||
|
||||
if (first_time) {
|
||||
memcpy(r, tmp, PRF_BLOCKLEN);
|
||||
(void)memcpy(r, tmp, PRF_BLOCKLEN);
|
||||
first_time = 0;
|
||||
} else
|
||||
memxor(r, tmp, PRF_BLOCKLEN);
|
||||
memcpy(data, tmp, PRF_BLOCKLEN);
|
||||
(void)memcpy(data, tmp, PRF_BLOCKLEN);
|
||||
datalen = PRF_BLOCKLEN;
|
||||
}
|
||||
free(data);
|
||||
@ -113,16 +113,16 @@ prf_iterate(u_int8_t *r, const u_int8_t *P, int Plen,
|
||||
*/
|
||||
|
||||
int
|
||||
pkcs5_pbkdf2(u_int8_t **r, int dkLen, const u_int8_t *P, int Plen,
|
||||
const u_int8_t *S, int Slen, int c, int compat)
|
||||
pkcs5_pbkdf2(u_int8_t **r, size_t dkLen, const u_int8_t *P, size_t Plen,
|
||||
const u_int8_t *S, size_t Slen, size_t c, int compat)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
size_t i;
|
||||
size_t l;
|
||||
|
||||
/* sanity */
|
||||
if (!r)
|
||||
return -1;
|
||||
if (dkLen <= 0)
|
||||
if (dkLen == 0)
|
||||
return -1;
|
||||
if (c < 1)
|
||||
return -1;
|
||||
@ -134,7 +134,7 @@ pkcs5_pbkdf2(u_int8_t **r, int dkLen, const u_int8_t *P, int Plen,
|
||||
*r = emalloc(l * PRF_BLOCKLEN);
|
||||
|
||||
/* Step 3 */
|
||||
for (i=0; i < l; i++)
|
||||
for (i = 0; i < l; i++)
|
||||
prf_iterate(*r + (PRF_BLOCKLEN * i), P, Plen, S, Slen, c,
|
||||
(compat?i:i+1));
|
||||
|
||||
@ -170,7 +170,7 @@ pkcs5_pbkdf2(u_int8_t **r, int dkLen, const u_int8_t *P, int Plen,
|
||||
*/
|
||||
|
||||
static int
|
||||
pkcs5_pbkdf2_time(int dkLen, int c)
|
||||
pkcs5_pbkdf2_time(size_t dkLen, size_t c)
|
||||
{
|
||||
struct rusage start;
|
||||
struct rusage end;
|
||||
@ -179,12 +179,12 @@ pkcs5_pbkdf2_time(int dkLen, int c)
|
||||
u_int8_t P[CAL_PASSLEN];
|
||||
u_int8_t S[CAL_SALTLEN];
|
||||
|
||||
getrusage(RUSAGE_SELF, &start);
|
||||
(void)getrusage(RUSAGE_SELF, &start);
|
||||
/* XXX compat flag at end to be removed when _OLD keygen method is */
|
||||
ret = pkcs5_pbkdf2(&r, dkLen, P, sizeof(P), S, sizeof(S), c, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
getrusage(RUSAGE_SELF, &end);
|
||||
(void)getrusage(RUSAGE_SELF, &end);
|
||||
free(r);
|
||||
|
||||
return (end.ru_utime.tv_sec - start.ru_utime.tv_sec) * 1000000
|
||||
@ -192,25 +192,25 @@ pkcs5_pbkdf2_time(int dkLen, int c)
|
||||
}
|
||||
|
||||
int
|
||||
pkcs5_pbkdf2_calibrate(int dkLen, int microseconds)
|
||||
pkcs5_pbkdf2_calibrate(size_t dkLen, int microseconds)
|
||||
{
|
||||
int c;
|
||||
size_t c;
|
||||
int t = 0;
|
||||
int ret;
|
||||
size_t ret;
|
||||
|
||||
/*
|
||||
* First we get a meaningfully long time by doubling the
|
||||
* iteration count until it takes longer than CAL_TIME. This
|
||||
* should take approximately 2 * CAL_TIME.
|
||||
*/
|
||||
for (c=1;; c *= 2) {
|
||||
for (c = 1;; c *= 2) {
|
||||
t = pkcs5_pbkdf2_time(dkLen, c);
|
||||
if (t > CAL_TIME)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Now that we know that, we scale it. */
|
||||
ret = (int) ((u_int64_t) c * microseconds / t);
|
||||
ret = (size_t) ((u_int64_t) c * microseconds / t);
|
||||
|
||||
/*
|
||||
* Since it is quite important to not get this wrong,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pkcs5_pbkdf2.h,v 1.3 2004/03/17 01:29:13 dan Exp $ */
|
||||
/* $NetBSD: pkcs5_pbkdf2.h,v 1.4 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -40,8 +40,8 @@
|
||||
#define PKCS5_PBKDF2_H
|
||||
|
||||
__BEGIN_DECLS
|
||||
int pkcs5_pbkdf2(u_int8_t **, int, const u_int8_t *, int,
|
||||
const u_int8_t *, int, int, int);
|
||||
int pkcs5_pbkdf2_calibrate(int, int);
|
||||
int pkcs5_pbkdf2(u_int8_t **, size_t, const u_int8_t *, size_t,
|
||||
const u_int8_t *, size_t, size_t, int);
|
||||
int pkcs5_pbkdf2_calibrate(size_t, int);
|
||||
__END_DECLS
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: utils.c,v 1.16 2007/02/06 00:48:37 cbiere Exp $ */
|
||||
/* $NetBSD: utils.c,v 1.17 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: utils.c,v 1.16 2007/02/06 00:48:37 cbiere Exp $");
|
||||
__RCSID("$NetBSD: utils.c,v 1.17 2007/11/06 02:50:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -141,19 +141,19 @@ memxor(void *res, const void *src, size_t len)
|
||||
/* for now we use a very simple encoding */
|
||||
|
||||
struct string {
|
||||
int length;
|
||||
char *text;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
string_t *
|
||||
string_new(const char *intext, int inlength)
|
||||
string_new(const char *intext, size_t inlength)
|
||||
{
|
||||
string_t *out;
|
||||
|
||||
out = emalloc(sizeof(*out));
|
||||
out->length = inlength;
|
||||
out->text = emalloc(out->length + 1);
|
||||
memcpy(out->text, intext, out->length);
|
||||
(void)memcpy(out->text, intext, out->length);
|
||||
out->text[out->length] = '\0';
|
||||
return out;
|
||||
}
|
||||
@ -191,8 +191,8 @@ string_add(const string_t *a1, const string_t *a2)
|
||||
sum = emalloc(sizeof(*sum));
|
||||
sum->length = a1->length + a2->length;
|
||||
sum->text = emalloc(sum->length + 1);
|
||||
memcpy(sum->text, a1->text, a1->length);
|
||||
memcpy(sum->text + a1->length, a2->text, a2->length);
|
||||
(void)memcpy(sum->text, a1->text, a1->length);
|
||||
(void)memcpy(sum->text + a1->length, a2->text, a2->length);
|
||||
sum->text[sum->length] = '\0';
|
||||
return sum;
|
||||
}
|
||||
@ -229,7 +229,7 @@ string_fromint(int in)
|
||||
|
||||
ret = emalloc(sizeof(*ret));
|
||||
ret->length = asprintf(&ret->text, "%d", in);
|
||||
if (ret->length == -1)
|
||||
if (ret->text == NULL)
|
||||
err(1, NULL);
|
||||
return ret;
|
||||
}
|
||||
@ -237,24 +237,23 @@ string_fromint(int in)
|
||||
void
|
||||
string_fprint(FILE *f, const string_t *s)
|
||||
{
|
||||
|
||||
fwrite(s->text, s->length, 1, f);
|
||||
(void)fwrite(s->text, s->length, 1, f);
|
||||
}
|
||||
|
||||
struct bits {
|
||||
int length;
|
||||
size_t length;
|
||||
char *text;
|
||||
};
|
||||
|
||||
bits_t *
|
||||
bits_new(const void *buf, int len)
|
||||
bits_new(const void *buf, size_t len)
|
||||
{
|
||||
bits_t *b;
|
||||
|
||||
b = emalloc(sizeof(*b));
|
||||
b->length = len;
|
||||
b->text = emalloc(BITS2BYTES(b->length));
|
||||
memcpy(b->text, buf, BITS2BYTES(b->length));
|
||||
(void)memcpy(b->text, buf, BITS2BYTES(b->length));
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -290,7 +289,7 @@ bits_getbuf(bits_t *in)
|
||||
return in->text;
|
||||
}
|
||||
|
||||
int
|
||||
size_t
|
||||
bits_len(bits_t *in)
|
||||
{
|
||||
|
||||
@ -348,32 +347,32 @@ bits_t *
|
||||
bits_decode(const string_t *in)
|
||||
{
|
||||
bits_t *ret;
|
||||
int len;
|
||||
int nbits;
|
||||
u_char *tmp;
|
||||
size_t len;
|
||||
size_t nbits;
|
||||
u_int32_t *tmp;
|
||||
|
||||
len = in->length;
|
||||
tmp = emalloc(len);
|
||||
|
||||
len = __b64_pton(in->text, tmp, len);
|
||||
len = __b64_pton(in->text, (void *)tmp, len);
|
||||
|
||||
if (len == -1) {
|
||||
fprintf(stderr, "bits_decode: mangled base64 stream\n");
|
||||
fprintf(stderr, " %s\n", in->text);
|
||||
if (len == (size_t)-1) {
|
||||
warnx("bits_decode: mangled base64 stream");
|
||||
warnx(" %s", in->text);
|
||||
free(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nbits = ntohl(*((u_int32_t *)tmp));
|
||||
if (nbits > (len - 4) * 8) {
|
||||
fprintf(stderr, "bits_decode: encoded bits claim to be "
|
||||
"longer than they are (nbits=%u, stream len=%u bytes)\n",
|
||||
(unsigned)nbits, (unsigned)len);
|
||||
nbits = ntohl(*tmp);
|
||||
if (nbits > (len - sizeof(*tmp)) * NBBY) {
|
||||
warnx("bits_decode: encoded bits claim to be "
|
||||
"longer than they are (nbits=%zu, stream len=%zu bytes)",
|
||||
nbits, len);
|
||||
free(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = bits_new(tmp+4, nbits);
|
||||
ret = bits_new(tmp + 1, nbits);
|
||||
free(tmp);
|
||||
return ret;
|
||||
}
|
||||
@ -392,23 +391,23 @@ string_t *
|
||||
bits_encode(const bits_t *in)
|
||||
{
|
||||
string_t *ret;
|
||||
int len;
|
||||
size_t len;
|
||||
char *out;
|
||||
u_char *tmp;
|
||||
u_int32_t *tmp;
|
||||
|
||||
if (!in)
|
||||
return NULL;
|
||||
|
||||
/* compute the total size of the input stream */
|
||||
len = BITS2BYTES(in->length) + 4;
|
||||
len = BITS2BYTES(in->length) + sizeof(*tmp);
|
||||
|
||||
tmp = emalloc(len);
|
||||
out = emalloc(len * 2);
|
||||
/* stuff the length up front */
|
||||
*((u_int32_t *)tmp) = htonl(in->length);
|
||||
memcpy(tmp + 4, in->text, len - 4);
|
||||
*tmp = htonl(in->length);
|
||||
(void)memcpy(tmp + 1, in->text, len - sizeof(*tmp));
|
||||
|
||||
if ((len = __b64_ntop(tmp, len, out, len * 2)) == -1) {
|
||||
if ((len = __b64_ntop((void *)tmp, len, out, len * 2)) == (size_t)-1) {
|
||||
free(out);
|
||||
free(tmp);
|
||||
return NULL;
|
||||
@ -430,7 +429,7 @@ bits_encode_d(bits_t *in)
|
||||
}
|
||||
|
||||
bits_t *
|
||||
bits_fget(FILE *f, int len)
|
||||
bits_fget(FILE *f, size_t len)
|
||||
{
|
||||
bits_t *bits;
|
||||
int ret;
|
||||
@ -447,7 +446,7 @@ bits_fget(FILE *f, int len)
|
||||
}
|
||||
|
||||
bits_t *
|
||||
bits_cget(const char *fn, int len)
|
||||
bits_cget(const char *fn, size_t len)
|
||||
{
|
||||
bits_t *bits;
|
||||
FILE *f;
|
||||
@ -457,12 +456,12 @@ bits_cget(const char *fn, int len)
|
||||
return NULL;
|
||||
|
||||
bits = bits_fget(f, len);
|
||||
fclose(f);
|
||||
(void)fclose(f);
|
||||
return bits;
|
||||
}
|
||||
|
||||
bits_t *
|
||||
bits_getrandombits(int len, int hard)
|
||||
bits_getrandombits(size_t len, int hard)
|
||||
{
|
||||
|
||||
return bits_cget((hard ? "/dev/random" : "/dev/urandom"), len);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: utils.h,v 1.6 2006/08/26 18:14:28 christos Exp $ */
|
||||
/* $NetBSD: utils.h,v 1.7 2007/11/06 02:50:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -57,7 +57,7 @@ void memxor(void *, const void *, size_t);
|
||||
|
||||
void free_notnull(void *);
|
||||
|
||||
string_t *string_new(const char *, int);
|
||||
string_t *string_new(const char *, size_t);
|
||||
string_t *string_dup(const string_t *);
|
||||
void string_assign(string_t **, string_t *);
|
||||
void string_free(string_t *);
|
||||
@ -69,12 +69,12 @@ string_t *string_fromint(int);
|
||||
|
||||
void string_fprint(FILE *, const string_t *);
|
||||
|
||||
bits_t *bits_new(const void *, int);
|
||||
bits_t *bits_new(const void *, size_t);
|
||||
bits_t *bits_dup(const bits_t *);
|
||||
void bits_assign(bits_t **, bits_t *);
|
||||
void bits_free(bits_t *);
|
||||
const void *bits_getbuf(bits_t *);
|
||||
int bits_len(bits_t *);
|
||||
size_t bits_len(bits_t *);
|
||||
int bits_match(const bits_t *, const bits_t *);
|
||||
|
||||
bits_t *bits_xor(const bits_t *, const bits_t *);
|
||||
@ -85,9 +85,9 @@ bits_t *bits_decode_d(string_t *);
|
||||
string_t *bits_encode(const bits_t *);
|
||||
string_t *bits_encode_d(bits_t *);
|
||||
|
||||
bits_t *bits_cget(const char *, int);
|
||||
bits_t *bits_fget(FILE *, int);
|
||||
bits_t *bits_getrandombits(int, int);
|
||||
bits_t *bits_cget(const char *, size_t);
|
||||
bits_t *bits_fget(FILE *, size_t);
|
||||
bits_t *bits_getrandombits(size_t, int);
|
||||
|
||||
void bits_fprint(FILE *, const bits_t *);
|
||||
__END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user