keygen.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2009, 2012-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: keygen.c,v 1.4 2009/11/12 14:02:38 marka Exp $ */
/*! \file */
#include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <isc/keyboard.h>
#include <dns/keyvalues.h>
#include "util.h"
#include "keygen.h"
/*%
* Convert algorithm type to string.
*/
const char *
switch (alg) {
case DST_ALG_HMACMD5:
return "hmac-md5";
case DST_ALG_HMACSHA1:
return "hmac-sha1";
case DST_ALG_HMACSHA224:
return "hmac-sha224";
case DST_ALG_HMACSHA256:
return "hmac-sha256";
case DST_ALG_HMACSHA384:
return "hmac-sha384";
case DST_ALG_HMACSHA512:
return "hmac-sha512";
default:
return "(unknown)";
}
}
/*%
* Convert string to algorithm type.
*/
alg_fromtext(const char *name) {
const char *p = name;
p = &name[5];
if (strcasecmp(p, "md5") == 0)
return DST_ALG_HMACMD5;
if (strcasecmp(p, "sha1") == 0)
return DST_ALG_HMACSHA1;
if (strcasecmp(p, "sha224") == 0)
return DST_ALG_HMACSHA224;
if (strcasecmp(p, "sha256") == 0)
return DST_ALG_HMACSHA256;
if (strcasecmp(p, "sha384") == 0)
return DST_ALG_HMACSHA384;
if (strcasecmp(p, "sha512") == 0)
return DST_ALG_HMACSHA512;
return DST_ALG_UNKNOWN;
}
/*%
* Return default keysize for a given algorithm type.
*/
int
switch (alg) {
case DST_ALG_HMACMD5:
return 128;
case DST_ALG_HMACSHA1:
return 160;
case DST_ALG_HMACSHA224:
return 224;
case DST_ALG_HMACSHA256:
return 256;
case DST_ALG_HMACSHA384:
return 384;
case DST_ALG_HMACSHA512:
return 512;
default:
return 0;
}
}
/*%
* Generate a key of size 'keysize' using entropy source 'randomfile',
* and place it in 'key_txtbuffer'
*/
void
int entropy_flags = 0;
char key_rawsecret[64];
switch (alg) {
case DST_ALG_HMACMD5:
case DST_ALG_HMACSHA1:
case DST_ALG_HMACSHA224:
case DST_ALG_HMACSHA256:
fatal("keysize %d out of range (must be 1-512)\n",
keysize);
break;
case DST_ALG_HMACSHA384:
case DST_ALG_HMACSHA512:
fatal("keysize %d out of range (must be 1-1024)\n",
keysize);
break;
default:
}
randomfile = NULL;
}
keysize, 0, 0,
/*
* Shut down the entropy source now so the "stop typing" message
* does not muck with the output.
*/
if (entropy_source != NULL)
dst_key_free(&key);
}
/*%
* Write a key file to 'keyfile'. If 'user' is non-NULL,
* make that user the owner of the file. The key will have
* the name 'keyname' and the secret in the buffer 'secret'.
*/
void
dns_secalg_t alg) {
fatal("unable to set file owner\n");
}
"\tsecret \"%.*s\";\n};\n",
(int)isc_buffer_usedlength(secret),
(char *)isc_buffer_base(secret));
}