2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * rc4Context.cpp - glue between AppleCSPContext and ssleay RC4 implementation
21 * Written by Doug Mitchell 04/03/2001
24 #include "rc4Context.h"
26 RC4Context::~RC4Context()
29 CCCryptorRelease(rc4Key
);
35 * Standard CSPContext init, called from CSPFullPluginSession::init().
36 * Reusable, e.g., query followed by en/decrypt.
38 void RC4Context::init(
39 const Context
&context
,
43 uint8
*keyData
= NULL
;
45 /* obtain key from context */
46 symmetricKeyBits(context
, session(), CSSM_ALGID_RC4
,
47 encrypting
? CSSM_KEYUSE_ENCRYPT
: CSSM_KEYUSE_DECRYPT
,
49 if((keyLen
< kCCKeySizeMinRC4
) || (keyLen
> kCCKeySizeMaxRC4
)) {
50 CssmError::throwMe(CSSMERR_CSP_INVALID_ATTR_KEY
);
53 /* All other context attributes ignored */
54 /* init the low-level state */
55 (void) CCCryptorCreateWithMode(0, kCCModeRC4
, kCCAlgorithmRC4
, ccDefaultPadding
, NULL
, keyData
, keyLen
, NULL
, 0, 0, 0, &rc4Key
);
60 * All of these functions are called by CSPFullPluginSession.
62 void RC4Context::update(
64 size_t &inSize
, // in/out
66 size_t &outSize
) // in/out
68 (void) CCCryptorUpdate(rc4Key
, inp
, inSize
, outp
, inSize
, &outSize
);
71 /* remainding functions are trivial for any stream cipher */
72 void RC4Context::final(
78 size_t RC4Context::inputSize(
79 size_t outSize
) // input for given output size
84 size_t RC4Context::outputSize(
85 bool final
/*= false*/,
86 size_t inSize
/*= 0*/) // output for given input size
91 void RC4Context::minimumProgress(
93 size_t &out
) // minimum progress chunks