1 /* Copyright (c) 2006-2010, UNINETT AS
2 * Copyright (c) 2010-2012, NORDUnet A/S */
3 /* See LICENSE for licensing information. */
9 #include "radsecproxy.h"
10 #include "fticks_hashmac.h"
16 "usage: radsecproxy-hash [-h] [-k key] [-t type]\n"
17 #if defined (READ_CONFIG)
18 " -c configfile\tuse configuration from CONFIGFILE\n"
20 " -h\t\t\tdisplay this help and exit\n"
21 " -k key\t\tuse KEY for HMAC\n"
22 " -t type\t\tprint digest of type TYPE [mac|hmac]\n");
26 #define MYNAME "radsecproxy-hash"
29 main(int argc, char *argv[])
32 #if defined(READ_CONFIG)
38 enum { TYPE_HASH, TYPE_HMAC } type = TYPE_HASH;
40 while ((opt = getopt(argc, argv, "hk:t:")) != -1) {
42 #if defined(READ_CONFIG)
50 key = (uint8_t *) optarg;
53 if (strcmp(optarg, "hash") == 0)
55 else if (strcmp(optarg, "hmac") == 0)
65 while (fgets(mac, sizeof(mac), stdin) != NULL) {
66 if (type == TYPE_HASH) {
67 if (fticks_hashmac((uint8_t *) mac, NULL, sizeof(buf), buf) != 0) {
68 fprintf(stderr, "%s: out of memory\n", MYNAME);
72 else if (type == TYPE_HMAC) {
74 fprintf(stderr, "%s: generating HMAC requires a key, use `-k'\n",
78 if (fticks_hashmac((uint8_t *) mac, key, sizeof(buf), buf) != 0) {
79 fprintf(stderr, "%s: out of memory\n", MYNAME);
83 puts((const char *) buf);