1 /* Copyright (c) 2006-2010, UNINETT AS.
2 * Copyright (c) 2010, UNINETT AS, NORDUnet A/S.
3 * Copyright (c) 2010-2012, NORDUnet A/S. */
4 /* See LICENSE for licensing information. */
10 #include "radsecproxy.h"
11 #include "fticks_hashmac.h"
17 "usage: radsecproxy-hash [-h] [-k key] [-t type]\n"
18 #if defined (READ_CONFIG)
19 " -c configfile\tuse configuration from CONFIGFILE\n"
21 " -h\t\t\tdisplay this help and exit\n"
22 " -k key\t\tuse KEY for HMAC\n"
23 " -t type\t\tprint digest of type TYPE [mac|hmac]\n");
27 #define MYNAME "radsecproxy-hash"
30 main(int argc, char *argv[])
33 #if defined(READ_CONFIG)
39 enum { TYPE_HASH, TYPE_HMAC } type = TYPE_HASH;
41 while ((opt = getopt(argc, argv, "hk:t:")) != -1) {
43 #if defined(READ_CONFIG)
51 key = (uint8_t *) optarg;
54 if (strcmp(optarg, "hash") == 0)
56 else if (strcmp(optarg, "hmac") == 0)
66 while (fgets(mac, sizeof(mac), stdin) != NULL) {
67 if (type == TYPE_HASH) {
68 if (fticks_hashmac((uint8_t *) mac, NULL, sizeof(buf), buf) != 0) {
69 fprintf(stderr, "%s: out of memory\n", MYNAME);
73 else if (type == TYPE_HMAC) {
75 fprintf(stderr, "%s: generating HMAC requires a key, use `-k'\n",
79 if (fticks_hashmac((uint8_t *) mac, key, sizeof(buf), buf) != 0) {
80 fprintf(stderr, "%s: out of memory\n", MYNAME);
84 puts((const char *) buf);