summaryrefslogtreecommitdiff
path: root/cipher/md.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-01-17 16:42:23 +0000
committerWerner Koch <wk@gnupg.org>2003-01-17 16:42:23 +0000
commit86d60c15b97ab30b941731a70864e96403b77ec9 (patch)
tree6a1040f9d7a226df25bcf9dcc81ac6ff8a25ccd2 /cipher/md.c
parent9b8117f58f1bc0365ab13f7d26fdb41cb2414005 (diff)
downloadlibgcrypt-86d60c15b97ab30b941731a70864e96403b77ec9.tar.gz
* cipher.c (gcry_cipher_encrypt): Reworked so that the output will
never contain the plaintext even if the caller did not checked the return value. * md.c (gcry_md_get_algo): Changed error code to GCRYERR_GENERAL because we don't have an invalid md algo but no algorithm enabled. * pubkey.c (gcry_pk_genkey): Changed error code for bounds check of table parameters to GCRYERR_INTERNAL. * md.c (gcry_md_open): Partly reverted Timo's change from 2002-10-10 by removing the check for the algorithm. An algorithm of 0 is allowed and anyway we should not double check it or check it using a different function. Also fixed the flags check. * pubkey.c (gcry_pk_encrypt): Make sure that R_CIPH points to NULL on error. (gcry_pk_decrypt): Ditto for R_PLAIN. (gcry_pk_sign): Ditto for R_SIG. (gcry_pk_genkey): Ditto for R_KEY.
Diffstat (limited to 'cipher/md.c')
-rw-r--r--cipher/md.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/cipher/md.c b/cipher/md.c
index 572580a2..bd5f7a29 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -1,5 +1,5 @@
/* md.c - message digest dispatcher
- * Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -350,18 +350,16 @@ md_open( int algo, int secure, int hmac )
}
-GCRY_MD_HD
+/* Create a message digest object for algorithm ALGO. FLAGS may be
+ given as an bitwise OR of the gcry_md_flags values. ALGO may be
+ given as 0 if the algorithms to be used are later set using
+ gcry_md_enable. */
+GcryMDHd
gcry_md_open (int algo, unsigned int flags)
{
GCRY_MD_HD hd;
- if (check_digest_algo (algo))
- {
- set_lasterr (GCRYERR_INV_MD_ALGO);
- return NULL;
- }
- if ((flags &~ GCRY_MD_FLAG_SECURE) > GCRY_MD_FLAG_SECURE
- && (flags &~ GCRY_MD_FLAG_HMAC) > GCRY_MD_FLAG_HMAC)
+ if ((flags & ~(GCRY_MD_FLAG_SECURE | GCRY_MD_FLAG_HMAC)))
{
set_lasterr (GCRYERR_INV_ARG);
return NULL;
@@ -537,9 +535,9 @@ md_write( GCRY_MD_HD a, byte *inbuf, size_t inlen)
void
-gcry_md_write( GCRY_MD_HD hd, const byte *inbuf, size_t inlen)
+gcry_md_write( GCRY_MD_HD hd, const void *inbuf, size_t inlen)
{
- md_write( hd, (byte*)inbuf, inlen );
+ md_write( hd, (unsigned char *)inbuf, inlen );
}
@@ -634,7 +632,7 @@ gcry_md_ctl( GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen)
int
-gcry_md_setkey( GCRY_MD_HD hd, const char *key, size_t keylen )
+gcry_md_setkey( GCRY_MD_HD hd, const void *key, size_t keylen )
{
int rc = 0;
@@ -753,7 +751,7 @@ gcry_md_get( GCRY_MD_HD hd, int algo, byte *buffer, int buflen )
* abort on an invalid algo. DISABLED_ALGOS are ignored here.
*/
void
-gcry_md_hash_buffer( int algo, char *digest, const char *buffer, size_t length)
+gcry_md_hash_buffer( int algo, void *digest, const void *buffer, size_t length)
{
if( algo == GCRY_MD_RMD160 )
_gcry_rmd160_hash_buffer( digest, buffer, length );
@@ -789,7 +787,7 @@ gcry_md_get_algo (GCRY_MD_HD hd)
int algo = md_get_algo (hd);
if (!algo)
{
- set_lasterr (GCRYERR_INV_MD_ALGO);
+ set_lasterr (GCRYERR_GENERAL);
return 0;
}
return algo;
@@ -1000,3 +998,6 @@ gcry_md_info( GCRY_MD_HD h, int cmd, void *buffer, size_t *nbytes)
return 0;
}
+
+
+