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