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:
105
libssh/wrapper.c
105
libssh/wrapper.c
@@ -90,29 +90,33 @@ void md5_final(unsigned char *md, MD5CTX c) {
|
|||||||
gcry_md_close(c);
|
gcry_md_close(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){
|
|
||||||
case HMAC_SHA1:
|
switch(type) {
|
||||||
gcry_md_open(&c,GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
|
case HMAC_SHA1:
|
||||||
break;
|
gcry_md_open(&c, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
|
||||||
case HMAC_MD5:
|
break;
|
||||||
gcry_md_open(&c,GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
|
case HMAC_MD5:
|
||||||
break;
|
gcry_md_open(&c, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
|
||||||
default:
|
break;
|
||||||
c=NULL;
|
default:
|
||||||
}
|
c = NULL;
|
||||||
gcry_md_setkey(c,key,len);
|
}
|
||||||
return c;
|
|
||||||
}
|
gcry_md_setkey(c, key, len);
|
||||||
void hmac_update(HMACCTX c, const void *data, unsigned long len){
|
|
||||||
gcry_md_write(c,data,len);
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmac_final(HMACCTX c,unsigned char *hashmacbuf,unsigned int *len){
|
void hmac_update(HMACCTX c, const void *data, unsigned long len) {
|
||||||
*len = gcry_md_get_algo_dlen(gcry_md_get_algo(c));
|
gcry_md_write(c, data, len);
|
||||||
memcpy(hashmacbuf, gcry_md_read(c, 0), *len);
|
}
|
||||||
gcry_md_close(c);
|
|
||||||
|
void hmac_final(HMACCTX c, unsigned char *hashmacbuf, unsigned int *len) {
|
||||||
|
*len = gcry_md_get_algo_dlen(gcry_md_get_algo(c));
|
||||||
|
memcpy(hashmacbuf, gcry_md_read(c, 0), *len);
|
||||||
|
gcry_md_close(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the wrapper functions for blowfish */
|
/* the wrapper functions for blowfish */
|
||||||
@@ -298,40 +302,47 @@ void md5_final(unsigned char *md, MD5CTX c) {
|
|||||||
SAFE_FREE(c);
|
SAFE_FREE(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));
|
||||||
|
if (ctx == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ctx = malloc(sizeof(*ctx));
|
|
||||||
if (ctx == 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){
|
|
||||||
case HMAC_SHA1:
|
switch(type) {
|
||||||
HMAC_Init(ctx,key,len,EVP_sha1());
|
case HMAC_SHA1:
|
||||||
break;
|
HMAC_Init(ctx, key, len, EVP_sha1());
|
||||||
case HMAC_MD5:
|
break;
|
||||||
HMAC_Init(ctx,key,len,EVP_md5());
|
case HMAC_MD5:
|
||||||
break;
|
HMAC_Init(ctx, key, len, EVP_md5());
|
||||||
default:
|
break;
|
||||||
free(ctx);
|
default:
|
||||||
ctx=NULL;
|
SAFE_FREE(ctx);
|
||||||
}
|
ctx = NULL;
|
||||||
return ctx;
|
}
|
||||||
|
|
||||||
|
return ctx;
|
||||||
}
|
}
|
||||||
void hmac_update(HMACCTX ctx,const void *data, unsigned long len){
|
|
||||||
HMAC_Update(ctx,data,len);
|
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);
|
void hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, unsigned int *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
|
||||||
|
|||||||
Reference in New Issue
Block a user