]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_transform/lib/SecEncryptTransform.cpp
Security-58286.200.222.tar.gz
[apple/security.git] / OSX / libsecurity_transform / lib / SecEncryptTransform.cpp
1 /*
2 * Copyright (c) 2010-2011 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 #include "SecEncryptTransform.h"
25 #include "SecTransformInternal.h"
26 #include "EncryptTransform.h"
27 #include <utilities/SecCFRelease.h>
28
29 /* --------------------------------------------------------------------------
30 Create the declared CFStringRefs
31 -------------------------------------------------------------------------- */
32
33 const CFStringRef __nonnull kSecPaddingNoneKey = CFSTR("SecPaddingNoneKey");
34 const CFStringRef __nonnull kSecPaddingPKCS1Key = CFSTR("SecPaddingPKCS1Key");
35 const CFStringRef __nonnull kSecPaddingPKCS5Key = CFSTR("SecPaddingPKCS5Key");
36 const CFStringRef __nonnull kSecPaddingPKCS7Key = CFSTR("SecPaddingPKCS7Key");
37 const CFStringRef __nonnull kSecPaddingOAEPKey = CFSTR("OAEPPadding");
38 const CFStringRef __nonnull kSecOAEPMGF1DigestAlgorithmAttributeName = CFSTR("OAEPMGF1DigestAlgo");
39
40 const CFStringRef __nonnull kSecModeNoneKey = CFSTR("SecModeNoneKey");
41 const CFStringRef __nonnull kSecModeECBKey = CFSTR("SecModeECBKey");
42 const CFStringRef __nonnull kSecModeCBCKey = CFSTR("SecModeCBCKey");
43 const CFStringRef __nonnull kSecModeCFBKey = CFSTR("SecModeCFBKey");
44 const CFStringRef __nonnull kSecModeOFBKey = CFSTR("SecModeOFBKey");
45
46 const CFStringRef __nonnull kSecOAEPMessageLengthAttributeName = CFSTR("OAEPMessageLength");
47 const CFStringRef __nonnull kSecOAEPEncodingParametersAttributeName = CFSTR("OAEPEncodingParameters");
48
49 const CFStringRef __nonnull kSecEncryptKey = CFSTR("SecEncryptKey");
50 const CFStringRef __nonnull kSecPaddingKey = CFSTR("SecPaddingKey");
51 const CFStringRef __nonnull kSecIVKey = CFSTR("SecIVKey");
52 const CFStringRef __nonnull kSecEncryptionMode = CFSTR("SecEncryptionMode");
53
54
55 SecTransformRef SecEncryptTransformCreate(SecKeyRef keyRef, CFErrorRef* error)
56 {
57 SecTransformRef etRef = EncryptTransform::Make();
58 EncryptTransform* et = (EncryptTransform*) CoreFoundationHolder::ObjectFromCFType(etRef);
59 if (et->InitializeObject(keyRef, error))
60 {
61 return etRef;
62 }
63 else
64 {
65
66 CFReleaseNull(etRef);
67 return NULL;
68 }
69 }
70
71
72 CFTypeID SecEncryptTransformGetTypeID()
73 {
74 return Transform::GetCFTypeID();
75 }
76
77 SecTransformRef SecDecryptTransformCreate(SecKeyRef keyRef, CFErrorRef* error)
78 {
79
80 SecTransformRef dtRef = DecryptTransform::Make();
81 DecryptTransform* dt = (DecryptTransform*) CoreFoundationHolder::ObjectFromCFType(dtRef);
82 if (dt->InitializeObject(keyRef, error))
83 {
84 return dtRef;
85 }
86 else
87 {
88 CFReleaseNull(dtRef);
89 return NULL;
90 }
91 }
92
93 CFTypeID SecDecryptTransformGetTypeID()
94 {
95 return Transform::GetCFTypeID();
96 }