]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/libDER/libDER/DER_Digest.h
734d752ca3c64625827b0c08b1d7e6df425f18aa
[apple/security.git] / OSX / libsecurity_keychain / libDER / libDER / DER_Digest.h
1 /*
2 * Copyright (c) 2005-2016 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 /*
26 * DER_Digest.h - DER encode a DigestInfo
27 *
28 */
29
30 #ifndef _DER_DIGEST_H_
31 #define _DER_DIGEST_H_
32
33 #include <libDER/libDER.h>
34
35 __BEGIN_DECLS
36
37 /*
38 * Create an encoded DigestInfo based on the specified SHA1 digest.
39 * The incoming digest must be 20 bytes long.
40 *
41 * Result is placed in caller's buffer, which must be at least of
42 * length DER_SHA1_DIGEST_INFO_LEN bytes.
43 *
44 * The *resultLen parameter is the available size in the result
45 * buffer on input, and the actual length of the encoded DigestInfo
46 * on output.
47 */
48 #define DER_SHA1_DIGEST_LEN 20
49 #define DER_SHA1_DIGEST_INFO_LEN 35
50
51 DERReturn DEREncodeSHA1DigestInfo(
52 const DERByte *sha1Digest,
53 DERSize sha1DigestLen,
54 DERByte *result, /* encoded result RETURNED here */
55 DERSize *resultLen); /* IN/OUT */
56
57 #define DER_SHA256_DIGEST_LEN 32
58 #define DER_SHA256_DIGEST_INFO_LEN 51
59
60 DERReturn DEREncodeSHA256DigestInfo(
61 const DERByte *sha256Digest,
62 DERSize sha256DigestLen,
63 DERByte *result, /* encoded result RETURNED here */
64 DERSize *resultLen); /* IN/OUT */
65
66 /*
67 * Likewise, create an encoded DIgestInfo for specified MD5 or MD2 digest.
68 */
69 #define DER_MD_DIGEST_LEN 16
70 #define DER_MD_DIGEST_INFO_LEN 34
71
72 typedef enum {
73 WD_MD2 = 1,
74 WD_MD5 = 2
75 } WhichDigest;
76
77 DERReturn DEREncodeMDDigestInfo(
78 WhichDigest whichDigest,
79 const DERByte *mdDigest,
80 DERSize mdDigestLen,
81 DERByte *result, /* encoded result RETURNED here */
82 DERSize *resultLen); /* IN/OUT */
83
84 /* max sizes you'll need in the general cases */
85 #define DER_MAX_DIGEST_LEN DER_SHA256_DIGEST_LEN
86 #define DER_MAX_ENCODED_INFO_LEN DER_SHA256_DIGEST_INFO_LEN
87
88 __END_DECLS
89
90 #endif /* _DER_DIGEST_H_ */
91