Commit bedc89e7 authored by Ben Laurie's avatar Ben Laurie
Browse files

Use HMAC instead of straight SHA-1.

parent d4635984
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ static HMAC_CTX hmac_ctx;

int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
	  EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
	  const char *file,const char *hmac_key);
	  const char *file,BIO *bmd,const char *hmac_key);

int MAIN(int, char **);

@@ -331,15 +331,13 @@ int MAIN(int argc, char **argv)

	/* we use md as a filter, reading from 'in' */
	BIO_set_md(bmd,md);
	if (hmac_key)
		HMAC_Init(&hmac_ctx,hmac_key,strlen(hmac_key),md);
	inp=BIO_push(bmd,in);

	if (argc == 0)
		{
		BIO_set_fp(in,stdin,BIO_NOCLOSE);
		err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
			  siglen,"","(stdin)",hmac_key);
			  siglen,"","(stdin)",bmd,hmac_key);
		}
	else
		{
@@ -357,15 +355,15 @@ int MAIN(int argc, char **argv)
				}
			if(!out_bin)
				{
				size_t len = strlen(name)+strlen(argv[i])+(hmac_key ? 4 : 0)+5;
				size_t len = strlen(name)+strlen(argv[i])+(hmac_key ? 5 : 0)+5;
				tmp=tofree=OPENSSL_malloc(len);
				BIO_snprintf(tmp,len,"%s%s(%s)= ",
							 hmac_key ? "HMAC_" : "",name,argv[i]);
							 hmac_key ? "HMAC-" : "",name,argv[i]);
				}
			else
				tmp="";
			r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
				siglen,tmp,argv[i],hmac_key);
				siglen,tmp,argv[i],bmd,hmac_key);
			if(r)
			    err=r;
			if(tofree)
@@ -390,11 +388,21 @@ end:

int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
	  EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
	  const char *file,const char *hmac_key)
	  const char *file,BIO *bmd,const char *hmac_key)
	{
	int len;
	int i;
	EVP_MD_CTX *md_ctx;

	if (hmac_key)
		{
		EVP_MD *md;

		BIO_get_md(bmd,&md);
		HMAC_Init(&hmac_ctx,hmac_key,strlen(hmac_key),md);
		BIO_get_md_ctx(bmd,&md_ctx);
		BIO_set_md_ctx(bmd,&hmac_ctx.md_ctx);
		}
	for (;;)
		{
		i=BIO_read(bp,(char *)buf,BUFSIZE);
@@ -438,11 +446,7 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
			}
		}
	else if(hmac_key)
		{
		EVP_MD_CTX *ctx;
		BIO_get_md_ctx(bp, &ctx);
		HMAC_Final(&hmac_ctx,buf,&len);
		}
	else
		len=BIO_gets(bp,(char *)buf,BUFSIZE);

@@ -458,6 +462,7 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
			}
		BIO_printf(out, "\n");
		}
	BIO_set_md_ctx(bmd,md_ctx);
	return 0;
	}
+1 −0
Original line number Diff line number Diff line
@@ -347,6 +347,7 @@ typedef struct bio_f_buffer_ctx_struct
#define BIO_C_NWRITE0				145
#define BIO_C_NWRITE				146
#define BIO_C_RESET_READ_REQUEST		147
#define BIO_C_SET_MD_CTX			148


#define BIO_set_app_data(s,arg)		BIO_set_ex_data(s,0,arg)
+6 −0
Original line number Diff line number Diff line
@@ -199,6 +199,12 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
		else
			ret=0;
		break;
	case BIO_C_SET_MD_CTX:
		if (b->init)
			b->ptr=ptr;
		else
			ret=0;
		break;
	case BIO_C_DO_STATE_MACHINE:
		BIO_clear_retry_flags(b);
		ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+1 −0
Original line number Diff line number Diff line
@@ -499,6 +499,7 @@ void BIO_set_md(BIO *,const EVP_MD *md);
#endif
#define BIO_get_md(b,mdp)		BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
#define BIO_get_md_ctx(b,mdcp)     BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
#define BIO_set_md_ctx(b,mdcp)     BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp)
#define BIO_get_cipher_status(b)	BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
#define BIO_get_cipher_ctx(b,c_pp)	BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)

+3 −3
Original line number Diff line number Diff line
SHA1(fips_aes_core.c)= 4cad001926dce3593181541ea19207256593171a
SHA1(fips_aes_selftest.c)= 8f270e559d34a18b3771d7f0098b77dd7bf168c5
SHA1(fips_aes_locl.h)= a3c01d9a4f9d5211e9e785852f6f1a2febfd73b6
HMAC-SHA1(fips_aes_core.c)= 979e9a3084dc8e15d9f222bf721e6faccf6bcd18
HMAC-SHA1(fips_aes_selftest.c)= 0bf32b515e2ee39332aa6563b45d7d44d88f4ed4
HMAC-SHA1(fips_aes_locl.h)= ded58f0cda8cb967dc5f5f3a860601c0b8744623
Loading