mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
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:
@@ -91,7 +91,8 @@ void md5_final(unsigned char *md, MD5CTX c) {
|
||||
}
|
||||
|
||||
HMACCTX hmac_init(const void *key, int len, int type) {
|
||||
HMACCTX c;
|
||||
HMACCTX c = NULL;
|
||||
|
||||
switch(type) {
|
||||
case HMAC_SHA1:
|
||||
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:
|
||||
c = NULL;
|
||||
}
|
||||
|
||||
gcry_md_setkey(c, key, len);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void hmac_update(HMACCTX c, const void *data, unsigned long 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 ctx;
|
||||
HMACCTX ctx = NULL;
|
||||
|
||||
ctx = malloc(sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef OLD_CRYPTO
|
||||
HMAC_CTX_init(ctx); // openssl 0.9.7 requires it.
|
||||
#endif
|
||||
|
||||
switch(type) {
|
||||
case HMAC_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());
|
||||
break;
|
||||
default:
|
||||
free(ctx);
|
||||
SAFE_FREE(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void hmac_update(HMACCTX ctx, const void *data, unsigned long len) {
|
||||
HMAC_Update(ctx, data, len);
|
||||
}
|
||||
|
||||
void hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, unsigned int *len) {
|
||||
HMAC_Final(ctx,hashmacbuf,len);
|
||||
|
||||
#ifndef OLD_CRYPTO
|
||||
HMAC_CTX_cleanup(ctx);
|
||||
#else
|
||||
HMAC_cleanup(ctx);
|
||||
#endif
|
||||
free(ctx);
|
||||
|
||||
SAFE_FREE(ctx);
|
||||
}
|
||||
|
||||
#ifdef HAS_BLOWFISH
|
||||
|
||||
Reference in New Issue
Block a user