1 /* Copyright (c) 2011,2013, NORDUnet A/S */
2 /* See LICENSE for licensing information. */
8 #include "radsecproxy.h"
9 #include "fticks_hashmac.h"
15 "usage: radsecproxy-hash [-h] [-k key] [-t type]\n"
16 #if defined (READ_CONFIG)
17 " -c configfile\tuse configuration from CONFIGFILE\n"
19 " -h\t\t\tdisplay this help and exit\n"
20 " -k key\t\tuse KEY for HMAC\n"
21 " -t type\t\tprint digest of type TYPE [mac|hmac]\n");
25 #define MYNAME "radsecproxy-hash"
28 main(int argc, char *argv[])
31 #if defined(READ_CONFIG)
37 enum { TYPE_HASH, TYPE_HMAC } type = TYPE_HASH;
39 while ((opt = getopt(argc, argv, "hk:t:")) != -1) {
41 #if defined(READ_CONFIG)
49 key = (uint8_t *) optarg;
52 if (strcmp(optarg, "hash") == 0)
54 else if (strcmp(optarg, "hmac") == 0)
64 while (fgets(mac, sizeof(mac), stdin) != NULL) {
65 if (type == TYPE_HASH) {
66 if (fticks_hashmac((uint8_t *) mac, NULL, sizeof(buf), buf) != 0) {
67 fprintf(stderr, "%s: out of memory\n", MYNAME);
71 else if (type == TYPE_HMAC) {
73 fprintf(stderr, "%s: generating HMAC requires a key, use `-k'\n",
77 if (fticks_hashmac((uint8_t *) mac, key, sizeof(buf), buf) != 0) {
78 fprintf(stderr, "%s: out of memory\n", MYNAME);
82 puts((const char *) buf);
88 /* Local Variables: */
89 /* c-file-style: "stroustrup" */