Reformat HMAC functions.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@518 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-17 12:03:59 +00:00
parent 42bdb90751
commit 32fd37d1ad

View File

@@ -91,7 +91,8 @@ void md5_final(unsigned char *md, MD5CTX c) {
} }
HMACCTX hmac_init(const void *key, int len, int type) { HMACCTX hmac_init(const void *key, int len, int type) {
HMACCTX c; HMACCTX c = NULL;
switch(type) { switch(type) {
case HMAC_SHA1: case HMAC_SHA1:
gcry_md_open(&c, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); gcry_md_open(&c, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
@@ -102,9 +103,12 @@ HMACCTX hmac_init(const void *key, int len,int type){
default: default:
c = NULL; c = NULL;
} }
gcry_md_setkey(c, key, len); gcry_md_setkey(c, key, len);
return c; return c;
} }
void hmac_update(HMACCTX c, const void *data, unsigned long len) { void hmac_update(HMACCTX c, const void *data, unsigned long len) {
gcry_md_write(c, data, len); gcry_md_write(c, data, len);
} }
@@ -299,15 +303,17 @@ void md5_final(unsigned char *md, MD5CTX c) {
} }
HMACCTX hmac_init(const void *key, int len, int type) { HMACCTX hmac_init(const void *key, int len, int type) {
HMACCTX ctx; HMACCTX ctx = NULL;
ctx = malloc(sizeof(*ctx)); ctx = malloc(sizeof(*ctx));
if (ctx == NULL) { if (ctx == NULL) {
return NULL; return NULL;
} }
#ifndef OLD_CRYPTO #ifndef OLD_CRYPTO
HMAC_CTX_init(ctx); // openssl 0.9.7 requires it. HMAC_CTX_init(ctx); // openssl 0.9.7 requires it.
#endif #endif
switch(type) { switch(type) {
case HMAC_SHA1: case HMAC_SHA1:
HMAC_Init(ctx, key, len, EVP_sha1()); HMAC_Init(ctx, key, len, EVP_sha1());
@@ -316,22 +322,27 @@ HMACCTX hmac_init(const void *key, int len,int type){
HMAC_Init(ctx, key, len, EVP_md5()); HMAC_Init(ctx, key, len, EVP_md5());
break; break;
default: default:
free(ctx); SAFE_FREE(ctx);
ctx = NULL; ctx = NULL;
} }
return ctx; return ctx;
} }
void hmac_update(HMACCTX ctx, const void *data, unsigned long len) { void hmac_update(HMACCTX ctx, const void *data, unsigned long len) {
HMAC_Update(ctx, data, len); HMAC_Update(ctx, data, len);
} }
void hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, unsigned int *len) { void hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, unsigned int *len) {
HMAC_Final(ctx,hashmacbuf,len); HMAC_Final(ctx,hashmacbuf,len);
#ifndef OLD_CRYPTO #ifndef OLD_CRYPTO
HMAC_CTX_cleanup(ctx); HMAC_CTX_cleanup(ctx);
#else #else
HMAC_cleanup(ctx); HMAC_cleanup(ctx);
#endif #endif
free(ctx);
SAFE_FREE(ctx);
} }
#ifdef HAS_BLOWFISH #ifdef HAS_BLOWFISH