/*
* 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.
*/
/*
# 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__ */
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"))
gnutls_hash_fast(alg, data, datalen, hash);
- return (gnutls_hash_get_len(alg));
+ return ((ssize_t)gnutls_hash_get_len(alg));
}
#else
{
_cups_md5_state_t state; /* MD5 state info */
+ if (hashsize < 16)
+ goto too_small;
+
_cupsMD5Init(&state);
_cupsMD5Append(&state, data, datalen);
_cupsMD5Finish(&state, hash);
* '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 */