2 * Copyright (C) 2011 NORDUnet A/S
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
13 #include "radsecproxy.h"
14 #include "fticks_hashmac.h"
20 "usage: radsecproxy-hash [-h] [-k key] [-t type]\n"
21 #if defined (READ_CONFIG)
22 " -c configfile\tuse configuration from CONFIGFILE\n"
24 " -h\t\t\tdisplay this help and exit\n"
25 " -k key\t\tuse KEY for HMAC\n"
26 " -t type\t\tprint digest of type TYPE [mac|hmac]\n");
30 #define MYNAME "radsecproxy-hash"
33 main(int argc, char *argv[])
36 #if defined(READ_CONFIG)
42 enum { TYPE_HASH, TYPE_HMAC } type = TYPE_HASH;
44 while ((opt = getopt(argc, argv, "hk:t:")) != -1) {
46 #if defined(READ_CONFIG)
54 key = (uint8_t *) optarg;
57 if (strcmp(optarg, "hash") == 0)
59 else if (strcmp(optarg, "hmac") == 0)
69 while (fgets(mac, sizeof(mac), stdin) != NULL) {
70 if (type == TYPE_HASH) {
71 if (fticks_hashmac((uint8_t *) mac, NULL, sizeof(buf), buf) != 0) {
72 fprintf(stderr, "%s: out of memory\n", MYNAME);
76 else if (type == TYPE_HMAC) {
78 fprintf(stderr, "%s: generating HMAC requires a key, use `-k'\n",
82 if (fticks_hashmac((uint8_t *) mac, key, sizeof(buf), buf) != 0) {
83 fprintf(stderr, "%s: out of memory\n", MYNAME);
87 puts((const char *) buf);