]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/md5passwd.c
7d38fdcaaeb1d4b36cb6b8a4e9e376722728aec2
2 * "$Id: md5passwd.c,v 1.5.2.6 2003/01/07 18:26:27 mike Exp $"
4 * MD5 password support for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * httpMD5() - Compute the MD5 sum of the username:group:password.
29 * httpMD5Nonce() - Combine the MD5 sum of the username, group, and password
30 * with the server-supplied nonce value.
31 * httpMD5String() - Convert an MD5 sum to a character string.
35 * Include necessary headers...
43 * 'httpMD5()' - Compute the MD5 sum of the username:group:password.
46 char * /* O - MD5 sum */
47 httpMD5(const char *username
, /* I - User name */
48 const char *realm
, /* I - Realm name */
49 const char *passwd
, /* I - Password string */
50 char md5
[33]) /* O - MD5 string */
52 md5_state_t state
; /* MD5 state info */
53 md5_byte_t sum
[16]; /* Sum data */
54 char line
[256]; /* Line to sum */
58 * Compute the MD5 sum of the user name, group name, and password.
61 snprintf(line
, sizeof(line
), "%s:%s:%s", username
, realm
, passwd
);
63 md5_append(&state
, (md5_byte_t
*)line
, strlen(line
));
64 md5_finish(&state
, sum
);
70 return (httpMD5String(sum
, md5
));
75 * 'httpMD5Final()' - Combine the MD5 sum of the username, group, and password
76 * with the server-supplied nonce value, method, and
80 char * /* O - New sum */
81 httpMD5Final(const char *nonce
, /* I - Server nonce value */
82 const char *method
, /* I - METHOD (GET, POST, etc.) */
83 const char *resource
, /* I - Resource path */
84 char md5
[33]) /* IO - MD5 sum */
86 md5_state_t state
; /* MD5 state info */
87 md5_byte_t sum
[16]; /* Sum data */
88 char line
[1024]; /* Line of data */
89 char a2
[33]; /* Hash of method and resource */
93 * First compute the MD5 sum of the method and resource...
96 snprintf(line
, sizeof(line
), "%s:%s", method
, resource
);
98 md5_append(&state
, (md5_byte_t
*)line
, strlen(line
));
99 md5_finish(&state
, sum
);
100 httpMD5String(sum
, a2
);
103 * Then combine A1 (MD5 of username, realm, and password) with the nonce
104 * and A2 (method + resource) values to get the final MD5 sum for the
108 snprintf(line
, sizeof(line
), "%s:%s:%s", md5
, nonce
, a2
);
111 md5_append(&state
, (md5_byte_t
*)line
, strlen(line
));
112 md5_finish(&state
, sum
);
114 return (httpMD5String(sum
, md5
));
119 * 'httpMD5String()' - Convert an MD5 sum to a character string.
122 char * /* O - MD5 sum in hex */
123 httpMD5String(const md5_byte_t
*sum
, /* I - MD5 sum data */
124 char md5
[33]) /* O - MD5 sum in hex */
126 int i
; /* Looping var */
127 char *md5ptr
; /* Pointer into MD5 string */
128 static char *hex
= "0123456789abcdef";
133 * Convert the MD5 sum to hexadecimal...
136 for (i
= 16, md5ptr
= md5
; i
> 0; i
--, sum
++)
138 *md5ptr
++ = hex
[*sum
>> 4];
139 *md5ptr
++ = hex
[*sum
& 15];
149 * End of "$Id: md5passwd.c,v 1.5.2.6 2003/01/07 18:26:27 mike Exp $".