1/*
2 * Copyright (c) 2000,2002,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*
25 * ocspUtils.h - common utilities for OCSPD
26 */
27#ifndef	_OCSPD_UTILS_H_
28#define _OCSPD_UTILS_H_
29
30#ifdef	__cplusplus
31extern "C" {
32#endif
33
34#include <CommonCrypto/CommonDigest.h>
35#include <Security/cssmtype.h>
36#include <CoreFoundation/CoreFoundation.h>
37
38/*
39 * Compare two CSSM_DATAs, return CSSM_TRUE if identical.
40 */
41CSSM_BOOL ocspdCompareCssmData(
42	const CSSM_DATA *data1,
43	const CSSM_DATA *data2);
44
45/*
46 * Parse a GeneralizedTime string into a CFAbsoluteTime. Returns NULL_TIME on
47 * parse error. Fractional parts of a second are discarded.
48 */
49#define NULL_TIME	0.0
50
51CFAbsoluteTime genTimeToCFAbsTime(
52	const CSSM_DATA *strData);
53
54/*
55 * Convert CFAbsoluteTime to generalized time string, GMT format (4 digit year,
56 * trailing 'Z'). Caller allocated the output which is GENERAL_TIME_STRLEN bytes plus
57 * a NULL.
58 */
59#define GENERAL_TIME_STRLEN	15		/* NOT including trailing NULL */
60
61void cfAbsTimeToGgenTime(
62	CFAbsoluteTime		absTime,
63	char				*genTime);
64
65#define OCSPD_MAX_DIGEST_LEN		CC_SHA256_DIGEST_LENGTH
66
67void ocspdSha1(
68	const void		*data,
69	CC_LONG			len,
70	unsigned char	*md);			// allocd by caller, CC_SHA1_DIGEST_LENGTH bytes
71void ocspdMD5(
72	const void		*data,
73	CC_LONG			len,
74	unsigned char	*md);			// allocd by caller, CC_MD5_DIGEST_LENGTH bytes
75void ocspdMD4(
76	const void		*data,
77	CC_LONG			len,
78	unsigned char	*md);			// allocd by caller, CC_MD4_DIGEST_LENGTH bytes
79void ocspdSHA256(
80	const void		*data,
81	CC_LONG			len,
82	unsigned char	*md);			// allocd by caller, CC_SHA256_DIGEST_LENGTH bytes
83
84/*
85 * How many items in a NULL-terminated array of pointers?
86 */
87unsigned ocspdArraySize(
88	const void **array);
89
90#define CFRELEASE(cf)	\
91	if(cf != NULL) {	\
92		CFRelease(cf);	\
93	}
94
95#ifdef	__cplusplus
96}
97#endif
98
99#endif	/* _OCSPD_UTILS_H_ */
100