1 /* creates the md5global.h file.
2 * Derived from KTH kerberos library bits.c program
4 * $Id: makemd5.c,v 1.4 2003/02/13 19:55:52 rjs3 Exp $
7 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. The name "Carnegie Mellon University" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For permission or any other legal
24 * details, please contact
25 * Office of Technology Transfer
26 * Carnegie Mellon University
28 * Pittsburgh, PA 15213-3890
29 * (412) 268-4387, fax: (412) 268-7395
30 * tech-transfer@andrew.cmu.edu
32 * 4. Redistributions of any form whatsoever must retain the following
34 * "This product includes software developed by Computing Services
35 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 * Copyright (c) 1997, 1998 Kungliga Tekniska Högskolan
48 * (Royal Institute of Technology, Stockholm, Sweden).
49 * All rights reserved.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
55 * 1. Redistributions of source code must retain the above copyright
56 * notice, this list of conditions and the following disclaimer.
58 * 2. Redistributions in binary form must reproduce the above copyright
59 * notice, this list of conditions and the following disclaimer in the
60 * documentation and/or other materials provided with the distribution.
62 * 3. All advertising materials mentioning features or use of this software
63 * must display the following acknowledgement:
64 * This product includes software developed by Kungliga Tekniska
65 * Högskolan and its contributors.
67 * 4. Neither the name of the Institute nor the names of its contributors
68 * may be used to endorse or promote products derived from this software
69 * without specific prior written permission.
71 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
72 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
77 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
78 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
79 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
80 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
98 *p = toupper((int) *p);
104 #define BITSIZE(TYPE) \
106 int b = 0; TYPE x = 1, zero = 0; char *pre = "U"; \
107 char tmp[128], tmp2[128]; \
108 while(x){ x <<= 1; b++; if(x < zero) pre=""; } \
111 sprintf(tmp, "%sINT%d" , pre, len/8); \
112 sprintf(tmp2, "typedef %s %s;", #TYPE, tmp); \
114 tabs = 5 - strlen(tmp2) / 8; \
115 fprintf(f, "%s", tmp2); \
116 while(tabs-- > 0) fprintf(f, "\t"); \
117 fprintf(f, "/* %2d bits */\n", b); \
123 try_signed(FILE *f, int len)
125 BITSIZE(signed char);
129 #ifdef HAVE_LONG_LONG
132 fprintf(f, "/* There is no %d bit type */\n", len);
136 try_unsigned(FILE *f, int len)
138 BITSIZE(unsigned char);
139 BITSIZE(unsigned short);
140 BITSIZE(unsigned int);
141 BITSIZE(unsigned long);
142 #ifdef HAVE_LONG_LONG
143 BITSIZE(unsigned long long);
145 fprintf(f, "/* There is no %d bit type */\n", len);
148 static int print_pre(FILE *f)
151 "/* GLOBAL.H - RSAREF types and constants\n"
153 "#ifndef MD5GLOBAL_H\n"
154 "#define MD5GLOBAL_H\n"
156 "/* PROTOTYPES should be set to one if and only if the compiler supports\n"
157 " function argument prototyping.\n"
158 "The following makes PROTOTYPES default to 0 if it has not already\n"
159 " been defined with C compiler flags.\n"
161 "#ifndef PROTOTYPES\n"
162 "#define PROTOTYPES 0\n"
165 "/* POINTER defines a generic pointer type */\n"
166 "typedef unsigned char *POINTER;\n"
172 static int print_post(FILE *f)
175 "/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.\n"
176 "If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it\n"
177 "returns an empty list.\n"
180 "#define PROTO_LIST(list) list\n"
182 "#define PROTO_LIST(list) ()\n"
185 "#endif /* MD5GLOBAL_H */\n\n"
192 int main(int argc, char **argv)
204 hb = malloc(strlen(fn) + 5);
205 sprintf(hb, "__%s__", fn);
206 for(p = hb; *p; p++){
207 if(!isalnum((int) *p))
210 f = fopen(argv[1], "w");
217 #endif /* HAVE_INT8_T */
220 #endif /* HAVE_INT16_T */
223 #endif /* HAVE_INT32_T */
226 #endif /* HAVE_INT64_T */
228 #ifndef HAVE_U_INT8_T
230 #endif /* HAVE_INT8_T */
231 #ifndef HAVE_U_INT16_T
232 try_unsigned (f, 16);
233 #endif /* HAVE_U_INT16_T */
234 #ifndef HAVE_U_INT32_T
235 try_unsigned (f, 32);
236 #endif /* HAVE_U_INT32_T */
237 #ifndef HAVE_U_INT64_T
238 try_unsigned (f, 64);
239 #endif /* HAVE_U_INT64_T */