]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/md5passwd.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / md5passwd.c
index a0dc2cf5bd6e3abd3835af54554d9fdedee2a097..487c4466c2341e5a8678e7722c74cc8d32361597 100644 (file)
@@ -1,37 +1,25 @@
 /*
- * "$Id$"
+ * MD5 password support for CUPS (deprecated).
  *
- *   MD5 password support for CUPS.
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2005 by Easy Software Products.
  *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2005 by Easy Software Products.
- *
- *   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
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   httpMD5()       - Compute the MD5 sum of the username:group:password.
- *   httpMD5Nonce()  - Combine the MD5 sum of the username, group, and password
- *                     with the server-supplied nonce value.
- *   httpMD5String() - Convert an MD5 sum to a character string.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
+#include <cups/cups.h>
 #include "http-private.h"
 #include "string-private.h"
 
 
 /*
  * 'httpMD5()' - Compute the MD5 sum of the username:group:password.
+ *
+ * @deprecated@
  */
 
 char *                                 /* O - MD5 sum */
@@ -40,7 +28,6 @@ httpMD5(const char *username,         /* I - User name */
         const char *passwd,            /* I - Password string */
        char       md5[33])             /* O - MD5 string */
 {
-  _cups_md5_state_t    state;          /* MD5 state info */
   unsigned char                sum[16];        /* Sum data */
   char                 line[256];      /* Line to sum */
 
@@ -50,15 +37,13 @@ httpMD5(const char *username,               /* I - User name */
   */
 
   snprintf(line, sizeof(line), "%s:%s:%s", username, realm, passwd);
-  _cupsMD5Init(&state);
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
-  _cupsMD5Finish(&state, sum);
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
 
  /*
   * Return the sum...
   */
 
-  return (httpMD5String(sum, md5));
+  return ((char *)cupsHashString(sum, sizeof(sum), md5, 33));
 }
 
 
@@ -66,6 +51,8 @@ httpMD5(const char *username,         /* I - User name */
  * 'httpMD5Final()' - Combine the MD5 sum of the username, group, and password
  *                    with the server-supplied nonce value, method, and
  *                    request-uri.
+ *
+ * @deprecated@
  */
 
 char *                                 /* O - New sum */
@@ -74,7 +61,6 @@ httpMD5Final(const char *nonce,               /* I - Server nonce value */
             const char *resource,      /* I - Resource path */
              char       md5[33])       /* IO - MD5 sum */
 {
-  _cups_md5_state_t    state;          /* MD5 state info */
   unsigned char                sum[16];        /* Sum data */
   char                 line[1024];     /* Line of data */
   char                 a2[33];         /* Hash of method and resource */
@@ -85,9 +71,7 @@ httpMD5Final(const char *nonce,               /* I - Server nonce value */
   */
 
   snprintf(line, sizeof(line), "%s:%s", method, resource);
-  _cupsMD5Init(&state);
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
-  _cupsMD5Finish(&state, sum);
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
   httpMD5String(sum, a2);
 
  /*
@@ -97,17 +81,16 @@ httpMD5Final(const char *nonce,             /* I - Server nonce value */
   */
 
   snprintf(line, sizeof(line), "%s:%s:%s", md5, nonce, a2);
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
 
-  _cupsMD5Init(&state);
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
-  _cupsMD5Finish(&state, sum);
-
-  return (httpMD5String(sum, md5));
+  return ((char *)cupsHashString(sum, sizeof(sum), md5, 33));
 }
 
 
 /*
  * 'httpMD5String()' - Convert an MD5 sum to a character string.
+ *
+ * @deprecated@
  */
 
 char *                                 /* O - MD5 sum in hex */
@@ -115,28 +98,5 @@ httpMD5String(const unsigned char *sum,     /* I - MD5 sum data */
               char                md5[33])
                                        /* O - MD5 sum in hex */
 {
-  int          i;                      /* Looping var */
-  char         *md5ptr;                /* Pointer into MD5 string */
-  static const char hex[] = "0123456789abcdef";
-                                       /* Hex digits */
-
-
- /*
-  * Convert the MD5 sum to hexadecimal...
-  */
-
-  for (i = 16, md5ptr = md5; i > 0; i --, sum ++)
-  {
-    *md5ptr++ = hex[*sum >> 4];
-    *md5ptr++ = hex[*sum & 15];
-  }
-
-  *md5ptr = '\0';
-
-  return (md5);
+  return ((char *)cupsHashString(sum, 16, md5, 33));
 }
-
-
-/*
- * End of "$Id$".
- */