]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/hash.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / cups / hash.c
index aa6aca310fb0c913aa7ae360d5856d62d03333e5..c153c665591dff31a6bc7e5ab8614a4f90ae5715 100644 (file)
@@ -1,15 +1,10 @@
 /*
  * Hashing function for CUPS.
  *
- * Copyright 2015-2017 by Apple Inc.
+ * Copyright © 2015-2019 by Apple Inc.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * missing or damaged, see the license at "http://www.cups.org/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -21,8 +16,9 @@
 #  include <CommonCrypto/CommonDigest.h>
 #elif defined(HAVE_GNUTLS)
 #  include <gnutls/crypto.h>
+#  include "md5-internal.h"
 #else
-#  include "md5-private.h"
+#  include "md5-internal.h"
 #endif /* __APPLE__ */
 
 
@@ -190,8 +186,24 @@ cupsHashData(const char    *algorithm,     /* I - Algorithm name */
   unsigned char        temp[64];               /* Temporary hash buffer */
   size_t       tempsize = 0;           /* Truncate to this size? */
 
+
   if (!strcmp(algorithm, "md5"))
-    alg = GNUTLS_DIG_MD5;
+  {
+   /*
+    * Some versions of GNU TLS disable MD5 without warning...
+    */
+
+    _cups_md5_state_t  state;          /* MD5 state info */
+
+    if (hashsize < 16)
+      goto too_small;
+
+    _cupsMD5Init(&state);
+    _cupsMD5Append(&state, data, (int)datalen);
+    _cupsMD5Finish(&state, hash);
+
+    return (16);
+  }
   else if (!strcmp(algorithm, "sha"))
     alg = GNUTLS_DIG_SHA1;
   else if (!strcmp(algorithm, "sha2-224"))
@@ -235,7 +247,7 @@ cupsHashData(const char    *algorithm,      /* I - Algorithm name */
 
     gnutls_hash_fast(alg, data, datalen, hash);
 
-    return (gnutls_hash_get_len(alg));
+    return ((ssize_t)gnutls_hash_get_len(alg));
   }
 
 #else
@@ -247,6 +259,9 @@ cupsHashData(const char    *algorithm,      /* I - Algorithm name */
   {
     _cups_md5_state_t  state;          /* MD5 state info */
 
+    if (hashsize < 16)
+      goto too_small;
+
     _cupsMD5Init(&state);
     _cupsMD5Append(&state, data, datalen);
     _cupsMD5Finish(&state, hash);
@@ -280,6 +295,8 @@ cupsHashData(const char    *algorithm,      /* I - Algorithm name */
  * 'cupsHashString()' - Format a hash value as a hexadecimal string.
  *
  * The passed buffer must be at least 2 * hashsize + 1 characters in length.
+ *
+ * @since CUPS 2.2.7@
  */
 
 const char *                           /* O - Formatted string */