]>
git.saurik.com Git - apple/security.git/blob - libsecurity_ssl/lib/symCipher.c
2 * Copyright (c) 1999-2001,2005-2008,2010-2012 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * symCipher.c - CDSA-based symmetric cipher module
28 #include "sslContext.h"
29 #include "cryptType.h"
31 #include "sslMemory.h"
32 #include <CommonCrypto/CommonCryptor.h>
33 #include "symCipher.h"
36 * CommonCrypto-based symmetric cipher callouts
41 CipherContext
*cipherCtx
,
45 * Cook up a CCCryptorRef. Assumes:
46 * cipherCtx->symCipher.keyAlg
47 * cipherCtx->encrypting
51 * Resulting CCCryptorRef --> cipherCtx->cryptorRef
53 CCCryptorStatus ccrtn
;
54 CCOperation op
= cipherCtx
->encrypting
? kCCEncrypt
: kCCDecrypt
;
56 if(cipherCtx
->cryptorRef
) {
57 CCCryptorRelease(cipherCtx
->cryptorRef
);
58 cipherCtx
->cryptorRef
= NULL
;
61 ccrtn
= CCCryptorCreate(op
, cipherCtx
->symCipher
->keyAlg
,
62 0, /* options - no padding, default CBC */
63 key
, cipherCtx
->symCipher
->keySize
,
65 &cipherCtx
->cryptorRef
);
67 sslErrorLog("CCCryptorCreate returned %d\n", (int)ccrtn
);
68 return internalComponentErr
;
73 /* same for en/decrypt */
74 OSStatus
CCSymmEncryptDecrypt(
78 CipherContext
*cipherCtx
,
81 CCCryptorStatus ccrtn
;
83 ASSERT(cipherCtx
!= NULL
);
84 ASSERT(cipherCtx
->cryptorRef
!= NULL
);
85 if(cipherCtx
->cryptorRef
== NULL
) {
86 sslErrorLog("CCSymmEncryptDecrypt: NULL cryptorRef\n");
87 return internalComponentErr
;
90 ccrtn
= CCCryptorUpdate(cipherCtx
->cryptorRef
, src
, len
,
91 dest
, len
, &data_moved
);
92 assert(data_moved
== len
);
95 sslErrorLog("CCSymmEncryptDecrypt: returned %d\n", (int)ccrtn
);
96 return internalComponentErr
;
102 OSStatus
CCSymmFinish(
103 CipherContext
*cipherCtx
,
106 if(cipherCtx
->cryptorRef
) {
107 CCCryptorRelease(cipherCtx
->cryptorRef
);
108 cipherCtx
->cryptorRef
= NULL
;