/*
 hmac-ipfc.c 
 
 Simple software that takes key as argument and data in stdin to generate
 a HMAC-SHA1. This software is in use for wrapper without HMAC support 
 into the IPFC framework.  (check out http://www.conostix.com/ipfc/) 
   
 Copyright (C) 2000,2001 Alexandre Dulaunoy <adulau@thinkingsecure.com>
 Copyright (C) 2001 Conostix S.A. Luxembourg - Alexandre Dulaunoy <adulau@conostix.com>

 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.

 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.



*/

#include <stdio.h>   
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <openssl/hmac.h>

#define BIG 24000

int main(int argc, char *argv[])
{
	char c;
	int cpt = 0;
	char *p;
        char buffer[BIG]; 
	BIO *bio, *b64;	

	if (argc <= 1)
	{
		printf("usage is : hmac-ipfc <key>  \n and use stdin for the data to be signed \n");
		return(0);
	}

	while ((cpt = getc(stdin)) != EOF && cpt < BIG)
	{ 
		buffer[cpt++] = c; 
	}


	p=HMAC(EVP_sha1(),
                        argv[1], strlen(argv[1]),
                        buffer, strlen(buffer),
                        NULL,NULL);
	
	b64 = BIO_new(BIO_f_base64());
	bio = BIO_new_fp(stdout, BIO_NOCLOSE);
	bio = BIO_push(b64, bio);
	BIO_write(bio, p, strlen(p));
	BIO_flush(bio);
	BIO_free_all(bio);
	
	/*printf ("%s\n",p);*/
	return(0);
}

