1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1996-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
23 * sum(3) wrapper for solaris -lmd message digest library
26 typedef void (*Lmd_init_f
)(void*);
27 typedef void (*Lmd_update_f
)(void*, const void*, size_t);
28 typedef void (*Lmd_final_f
)(unsigned char*, void*);
34 Lmd_update_f updatef; \
36 unsigned int datasize; \
37 unsigned char total[64]; \
38 unsigned char data[64];
52 Lmd_t
* lmd
= (Lmd_t
*)p
;
54 (*lmd
->initf
)(&lmd
->context
);
59 lmd_block(Sum_t
* p
, const void* s
, size_t n
)
61 Lmd_t
* lmd
= (Lmd_t
*)p
;
63 (*lmd
->updatef
)(&lmd
->context
, s
, n
);
70 register Lmd_t
* lmd
= (Lmd_t
*)p
;
73 (*lmd
->finalf
)(lmd
->data
, &lmd
->context
);
74 for (i
= 0; i
< lmd
->datasize
; i
++)
75 lmd
->total
[i
] ^= lmd
->data
[i
];
80 lmd_print(Sum_t
* p
, Sfio_t
* sp
, register int flags
, size_t scale
)
82 register Lmd_t
* lmd
= (Lmd_t
*)p
;
83 register unsigned char* d
;
86 d
= (flags
& SUM_TOTAL
) ? lmd
->total
: lmd
->data
;
87 for (i
= 0; i
< lmd
->datasize
; i
++)
88 sfprintf(sp
, "%02x", d
[i
]);
93 lmd_data(Sum_t
* p
, Sumdata_t
* data
)
95 Lmd_t
* lmd
= (Lmd_t
*)p
;
97 data
->size
= lmd
->datasize
;
99 data
->buf
= lmd
->data
;
103 #if _lib_MD4Init && _hdr_md4
107 #define md4_description "RFC1320 MD4 message digest. Cryptographically weak. The block count is not printed."
108 #define md4_options "[+(version)?md4 (solaris -lmd) 2005-07-26]"
109 #define md4_match "md4|MD4"
111 #define md4_init lmd_init
112 #define md4_block lmd_block
113 #define md4_done lmd_done
114 #define md4_print lmd_print
115 #define md4_data lmd_data
124 md4_open(const Method_t
* method
, const char* name
)
128 if (lmd
= newof(0, Md4_t
, 1, 0))
130 lmd
->method
= (Method_t
*)method
;
133 lmd
->initf
= (Lmd_init_f
)MD4Init
;
134 lmd
->updatef
= (Lmd_update_f
)MD4Update
;
135 lmd
->finalf
= (Lmd_final_f
)MD4Final
;
136 md4_init((Sum_t
*)lmd
);
143 #if _lib_MD5Init && _hdr_md5
147 #define md5_description "RFC1321 MD5 message digest. Cryptographically weak. The block count is not printed."
148 #define md5_options "[+(version)?md5 (solaris -lmd) 2005-07-26]"
149 #define md5_match "md5|MD5"
151 #define md5_init lmd_init
152 #define md5_block lmd_block
153 #define md5_done lmd_done
154 #define md5_print lmd_print
155 #define md5_data lmd_data
164 md5_open(const Method_t
* method
, const char* name
)
168 if (lmd
= newof(0, Md5_t
, 1, 0))
170 lmd
->method
= (Method_t
*)method
;
173 lmd
->initf
= (Lmd_init_f
)MD5Init
;
174 lmd
->updatef
= (Lmd_update_f
)MD5Update
;
175 lmd
->finalf
= (Lmd_final_f
)MD5Final
;
176 md5_init((Sum_t
*)lmd
);
183 #if _lib_SHA1Init && _hdr_sha1
187 #define sha1_description "RFC3174 / FIPS 180-1 SHA-1 secure hash algorithm 1. Cryptographically weak. The block count is not printed."
188 #define sha1_options "[+(version)?sha1 (solaris -lmd) 2005-07-26]"
189 #define sha1_match "sha1|SHA1|sha-1|SHA-1"
191 #define sha1_init lmd_init
192 #define sha1_block lmd_block
193 #define sha1_done lmd_done
194 #define sha1_print lmd_print
195 #define sha1_data lmd_data
197 typedef struct Sha1_s
201 unsigned char pad
[1024]; /* XXX: who's bug is it? */
205 sha1_open(const Method_t
* method
, const char* name
)
209 if (lmd
= newof(0, Sha1_t
, 1, 0))
211 lmd
->method
= (Method_t
*)method
;
214 lmd
->initf
= (Lmd_init_f
)SHA1Init
;
215 lmd
->updatef
= (Lmd_update_f
)SHA1Update
;
216 lmd
->finalf
= (Lmd_final_f
)SHA1Final
;
217 sha1_init((Sum_t
*)lmd
);
224 #if _lib_SHA2Init && _hdr_sha2
228 #define sha256_description "FIPS 180-2 SHA256 secure hash algorithm. The block count is not printed."
229 #define sha256_options "[+(version)?sha256 (solaris -lmd) 2005-07-26]"
230 #define sha256_match "sha256|sha-256|SHA256|SHA-256"
231 #define sha256_scale 0
232 #define sha256_init lmd_init
233 #define sha256_block lmd_block
234 #define sha256_done lmd_done
235 #define sha256_print lmd_print
236 #define sha256_data lmd_data
238 typedef struct Sha256_s
245 sha256_open(const Method_t
* method
, const char* name
)
249 if (lmd
= newof(0, Sha256_t
, 1, 0))
251 lmd
->method
= (Method_t
*)method
;
254 lmd
->initf
= (Lmd_init_f
)SHA256Init
;
255 lmd
->updatef
= (Lmd_update_f
)SHA256Update
;
256 lmd
->finalf
= (Lmd_final_f
)SHA256Final
;
257 sha256_init((Sum_t
*)lmd
);
262 #define sha384_description "FIPS 180-2 SHA384 secure hash algorithm. The block count is not printed."
263 #define sha384_options "[+(version)?sha384 (solaris -lmd) 2005-07-26]"
264 #define sha384_match "sha384|sha-384|SHA384|SHA-384"
265 #define sha384_scale 0
266 #define sha384_init lmd_init
267 #define sha384_block lmd_block
268 #define sha384_done lmd_done
269 #define sha384_print lmd_print
270 #define sha384_data lmd_data
272 typedef struct Sha384_s
279 sha384_open(const Method_t
* method
, const char* name
)
283 if (lmd
= newof(0, Sha384_t
, 1, 0))
285 lmd
->method
= (Method_t
*)method
;
288 lmd
->initf
= (Lmd_init_f
)SHA384Init
;
289 lmd
->updatef
= (Lmd_update_f
)SHA384Update
;
290 lmd
->finalf
= (Lmd_final_f
)SHA384Final
;
291 sha384_init((Sum_t
*)lmd
);
296 #define sha512_description "FIPS 180-2 SHA512 secure hash algorithm. The block count is not printed."
297 #define sha512_options "[+(version)?sha512 (solaris -lmd) 2005-07-26]"
298 #define sha512_match "sha512|sha-512|SHA512|SHA-512"
299 #define sha512_scale 0
300 #define sha512_init lmd_init
301 #define sha512_block lmd_block
302 #define sha512_done lmd_done
303 #define sha512_print lmd_print
304 #define sha512_data lmd_data
306 typedef struct Sha512_s
313 sha512_open(const Method_t
* method
, const char* name
)
317 if (lmd
= newof(0, Sha512_t
, 1, 0))
319 lmd
->method
= (Method_t
*)method
;
322 lmd
->initf
= (Lmd_init_f
)SHA512Init
;
323 lmd
->updatef
= (Lmd_update_f
)SHA512Update
;
324 lmd
->finalf
= (Lmd_final_f
)SHA512Final
;
325 sha512_init((Sum_t
*)lmd
);