gss: pass GSS_C_NO_OID name type through to mechanism
[heimdal.git] / lib / hcrypto / evp-cc.c
blob4a377f1c3bb10fdef62aa0011f2537ad58246b59
1 /*
2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 /* CommonCrypto provider */
38 #ifdef __APPLE__
40 #include <config.h>
41 #include <roken.h>
43 #include <assert.h>
45 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
46 #include <CommonCrypto/CommonDigest.h>
47 #endif
48 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
49 #include <CommonCrypto/CommonCryptor.h>
50 #endif
52 #include <evp.h>
53 #include <evp-hcrypto.h>
54 #include <evp-cc.h>
60 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
62 struct cc_key {
63 CCCryptorRef href;
66 static int
67 cc_do_cipher(EVP_CIPHER_CTX *ctx,
68 unsigned char *out,
69 const unsigned char *in,
70 unsigned int size)
72 struct cc_key *cc = ctx->cipher_data;
73 CCCryptorStatus ret;
74 size_t moved;
76 memcpy(out, in, size);
78 ret = CCCryptorUpdate(cc->href, in, size, out, size, &moved);
79 if (ret)
80 return 0;
82 if (moved != size)
83 return 0;
85 return 1;
88 static int
89 cc_cleanup(EVP_CIPHER_CTX *ctx)
91 struct cc_key *cc = ctx->cipher_data;
92 if (cc->href)
93 CCCryptorRelease(cc->href);
94 return 1;
97 static int
98 init_cc_key(int encp, unsigned long flags,
99 CCAlgorithm alg, const void *key, size_t keylen,
100 const void *iv, CCCryptorRef *ref)
102 CCOperation op = encp ? kCCEncrypt : kCCDecrypt;
103 CCMode mode;
104 CCModeOptions options = 0;
105 CCCryptorStatus ret;
107 if (*ref) {
108 if (key == NULL && iv) {
109 CCCryptorReset(*ref, iv);
110 return 1;
112 CCCryptorRelease(*ref);
115 if (key) {
116 switch (flags & EVP_CIPH_MODE) {
117 case EVP_CIPH_STREAM_CIPHER:
118 mode = kCCModeRC4;
119 break;
120 case EVP_CIPH_CFB8_MODE:
121 mode = kCCModeCFB8;
122 break;
123 default:
124 mode = kCCModeCBC;
125 break;
128 ret = CCCryptorCreateWithMode(op, mode, alg, ccNoPadding,
129 iv, key, keylen, NULL, 0, 0,
130 options, ref);
131 if (ret)
132 return 0;
135 return 1;
138 static int
139 cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
140 const unsigned char * key,
141 const unsigned char * iv,
142 int encp)
144 struct cc_key *cc = ctx->cipher_data;
145 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithm3DES,
146 key, kCCKeySize3DES, iv, &cc->href);
149 #endif /* HAVE_COMMONCRYPTO_COMMONCRYPTOR_H */
152 * The triple DES cipher type (Apple CommonCrypto provider)
154 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
156 * @ingroup hcrypto_evp
159 const EVP_CIPHER *
160 EVP_cc_des_ede3_cbc(void)
162 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
163 static const EVP_CIPHER des_ede3_cbc = {
168 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
169 cc_des_ede3_cbc_init,
170 cc_do_cipher,
171 cc_cleanup,
172 sizeof(struct cc_key),
173 NULL,
174 NULL,
175 NULL,
176 NULL
178 return &des_ede3_cbc;
179 #elif HCRYPTO_FALLBACK
180 return EVP_hcrypto_des_ede3_cbc();
181 #else
182 return NULL;
183 #endif
186 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
191 static int
192 cc_des_cbc_init(EVP_CIPHER_CTX *ctx,
193 const unsigned char * key,
194 const unsigned char * iv,
195 int encp)
197 struct cc_key *cc = ctx->cipher_data;
198 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmDES,
199 key, kCCBlockSizeDES, iv, &cc->href);
201 #endif
204 * The DES cipher type (Apple CommonCrypto provider)
206 * @return the DES-CBC EVP_CIPHER pointer.
208 * @ingroup hcrypto_evp
211 const EVP_CIPHER *
212 EVP_cc_des_cbc(void)
214 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
215 static const EVP_CIPHER des_ede3_cbc = {
217 kCCBlockSizeDES,
218 kCCBlockSizeDES,
219 kCCBlockSizeDES,
220 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
221 cc_des_cbc_init,
222 cc_do_cipher,
223 cc_cleanup,
224 sizeof(struct cc_key),
225 NULL,
226 NULL,
227 NULL,
228 NULL
230 return &des_ede3_cbc;
231 #elif HCRYPTO_FALLBACK
232 return EVP_hcrypto_des_cbc();
233 #else
234 return NULL;
235 #endif
238 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
243 static int
244 cc_aes_cbc_init(EVP_CIPHER_CTX *ctx,
245 const unsigned char * key,
246 const unsigned char * iv,
247 int encp)
249 struct cc_key *cc = ctx->cipher_data;
250 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmAES128,
251 key, ctx->cipher->key_len, iv, &cc->href);
253 #endif
256 * The AES-128 cipher type (Apple CommonCrypto provider)
258 * @return the AES-128-CBC EVP_CIPHER pointer.
260 * @ingroup hcrypto_evp
263 const EVP_CIPHER *
264 EVP_cc_aes_128_cbc(void)
266 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
267 static const EVP_CIPHER c = {
269 kCCBlockSizeAES128,
270 kCCKeySizeAES128,
271 kCCBlockSizeAES128,
272 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
273 cc_aes_cbc_init,
274 cc_do_cipher,
275 cc_cleanup,
276 sizeof(struct cc_key),
277 NULL,
278 NULL,
279 NULL,
280 NULL
282 return &c;
283 #elif HCRYPTO_FALLBACK
284 return EVP_hcrypto_aes_128_cbc();
285 #else
286 return NULL;
287 #endif
291 * The AES-192 cipher type (Apple CommonCrypto provider)
293 * @return the AES-192-CBC EVP_CIPHER pointer.
295 * @ingroup hcrypto_evp
298 const EVP_CIPHER *
299 EVP_cc_aes_192_cbc(void)
301 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
302 static const EVP_CIPHER c = {
304 kCCBlockSizeAES128,
305 kCCKeySizeAES192,
306 kCCBlockSizeAES128,
307 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
308 cc_aes_cbc_init,
309 cc_do_cipher,
310 cc_cleanup,
311 sizeof(struct cc_key),
312 NULL,
313 NULL,
314 NULL,
315 NULL
317 return &c;
318 #elif HCRYPTO_FALLBACK
319 return EVP_hcrypto_aes_192_cbc();
320 #else
321 return NULL;
322 #endif
326 * The AES-256 cipher type (Apple CommonCrypto provider)
328 * @return the AES-256-CBC EVP_CIPHER pointer.
330 * @ingroup hcrypto_evp
333 const EVP_CIPHER *
334 EVP_cc_aes_256_cbc(void)
336 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
337 static const EVP_CIPHER c = {
339 kCCBlockSizeAES128,
340 kCCKeySizeAES256,
341 kCCBlockSizeAES128,
342 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
343 cc_aes_cbc_init,
344 cc_do_cipher,
345 cc_cleanup,
346 sizeof(struct cc_key),
347 NULL,
348 NULL,
349 NULL,
350 NULL
352 return &c;
353 #elif HCRYPTO_FALLBACK
354 return EVP_hcrypto_aes_256_cbc();
355 #else
356 return NULL;
357 #endif
360 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
365 static int
366 cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx,
367 const unsigned char * key,
368 const unsigned char * iv,
369 int encp)
371 struct cc_key *cc = ctx->cipher_data;
372 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmAES128,
373 key, ctx->cipher->key_len, NULL, &cc->href);
375 #endif
378 * The AES-128 CFB8 cipher type (Apple CommonCrypto provider)
380 * @return the AES-128-CFB8 EVP_CIPHER pointer.
382 * @ingroup hcrypto_evp
385 const EVP_CIPHER *
386 EVP_cc_aes_128_cfb8(void)
388 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
389 static const EVP_CIPHER c = {
392 kCCKeySizeAES128,
393 kCCBlockSizeAES128,
394 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
395 cc_aes_cfb8_init,
396 cc_do_cipher,
397 cc_cleanup,
398 sizeof(struct cc_key),
399 NULL,
400 NULL,
401 NULL,
402 NULL
404 return &c;
405 #elif HCRYPTO_FALLBACK
406 return EVP_hcrypto_aes_128_cfb8();
407 #else
408 return NULL;
409 #endif
413 * The AES-192 CFB8 cipher type (Apple CommonCrypto provider)
415 * @return the AES-192-CFB8 EVP_CIPHER pointer.
417 * @ingroup hcrypto_evp
420 const EVP_CIPHER *
421 EVP_cc_aes_192_cfb8(void)
423 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
424 static const EVP_CIPHER c = {
427 kCCKeySizeAES192,
428 kCCBlockSizeAES128,
429 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
430 cc_aes_cfb8_init,
431 cc_do_cipher,
432 cc_cleanup,
433 sizeof(struct cc_key),
434 NULL,
435 NULL,
436 NULL,
437 NULL
439 return &c;
440 #elif HCRYPTO_FALLBACK
441 return EVP_hcrypto_aes_192_cfb8();
442 #else
443 return NULL;
444 #endif
448 * The AES-256 CFB8 cipher type (Apple CommonCrypto provider)
450 * @return the AES-256-CFB8 EVP_CIPHER pointer.
452 * @ingroup hcrypto_evp
455 const EVP_CIPHER *
456 EVP_cc_aes_256_cfb8(void)
458 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
459 static const EVP_CIPHER c = {
461 kCCBlockSizeAES128,
462 kCCKeySizeAES256,
463 kCCBlockSizeAES128,
464 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
465 cc_aes_cfb8_init,
466 cc_do_cipher,
467 cc_cleanup,
468 sizeof(struct cc_key),
469 NULL,
470 NULL,
471 NULL,
472 NULL
474 return &c;
475 #elif HCRYPTO_FALLBACK
476 return EVP_hcrypto_aes_256_cfb8();
477 #else
478 return NULL;
479 #endif
486 #ifdef COMMONCRYPTO_SUPPORTS_RC2
487 static int
488 cc_rc2_cbc_init(EVP_CIPHER_CTX *ctx,
489 const unsigned char * key,
490 const unsigned char * iv,
491 int encp)
493 struct cc_key *cc = ctx->cipher_data;
494 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmRC2,
495 key, ctx->cipher->key_len, iv, &cc->href);
497 #endif
500 * The RC2 cipher type - common crypto
502 * @return the RC2 EVP_CIPHER pointer.
504 * @ingroup hcrypto_evp
508 const EVP_CIPHER *
509 EVP_cc_rc2_cbc(void)
511 #ifdef COMMONCRYPTO_SUPPORTS_RC2
512 static const EVP_CIPHER rc2_cbc = {
514 kCCBlockSizeRC2,
516 kCCBlockSizeRC2,
517 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
518 cc_rc2_cbc_init,
519 cc_do_cipher,
520 cc_cleanup,
521 sizeof(struct cc_key),
522 NULL,
523 NULL,
524 NULL,
525 NULL
527 return &rc2_cbc;
528 #elif HCRYPTO_FALLBACK
529 return EVP_hcrypto_rc2_cbc();
530 #else
531 return NULL;
532 #endif
536 * The RC2-40 cipher type - common crypto
538 * @return the RC2-40 EVP_CIPHER pointer.
540 * @ingroup hcrypto_evp
544 const EVP_CIPHER *
545 EVP_cc_rc2_40_cbc(void)
547 #ifdef COMMONCRYPTO_SUPPORTS_RC2
548 static const EVP_CIPHER rc2_40_cbc = {
550 kCCBlockSizeRC2,
552 kCCBlockSizeRC2,
553 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
554 cc_rc2_cbc_init,
555 cc_do_cipher,
556 cc_cleanup,
557 sizeof(struct cc_key),
558 NULL,
559 NULL,
560 NULL,
561 NULL
563 return &rc2_40_cbc;
564 #elif HCRYPTO_FALLBACK
565 return EVP_hcrypto_rc2_40_cbc();
566 #else
567 return NULL;
568 #endif
573 * The RC2-64 cipher type - common crypto
575 * @return the RC2-64 EVP_CIPHER pointer.
577 * @ingroup hcrypto_evp
581 const EVP_CIPHER *
582 EVP_cc_rc2_64_cbc(void)
584 #ifdef COMMONCRYPTO_SUPPORTS_RC2
585 static const EVP_CIPHER rc2_64_cbc = {
587 kCCBlockSizeRC2,
589 kCCBlockSizeRC2,
590 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
591 cc_rc2_cbc_init,
592 cc_do_cipher,
593 cc_cleanup,
594 sizeof(struct cc_key),
595 NULL,
596 NULL,
597 NULL,
598 NULL
600 return &rc2_64_cbc;
601 #elif HCRYPTO_FALLBACK
602 return EVP_hcrypto_rc2_64_cbc();
603 #else
604 return NULL;
605 #endif
609 * The CommonCrypto md2 provider
611 * @ingroup hcrypto_evp
614 const EVP_MD *
615 EVP_cc_md2(void)
617 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
618 static const struct hc_evp_md md2 = {
619 CC_MD2_DIGEST_LENGTH,
620 CC_MD2_BLOCK_BYTES,
621 sizeof(CC_MD2_CTX),
622 (hc_evp_md_init)CC_MD2_Init,
623 (hc_evp_md_update)CC_MD2_Update,
624 (hc_evp_md_final)CC_MD2_Final,
625 (hc_evp_md_cleanup)NULL
627 return &md2;
628 #elif HCRYPTO_FALLBACK
629 return EVP_hcrypto_md2();
630 #else
631 return NULL;
632 #endif
636 * The CommonCrypto md4 provider
638 * @ingroup hcrypto_evp
641 const EVP_MD *
642 EVP_cc_md4(void)
644 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
645 static const struct hc_evp_md md4 = {
646 CC_MD4_DIGEST_LENGTH,
647 CC_MD4_BLOCK_BYTES,
648 sizeof(CC_MD4_CTX),
649 (hc_evp_md_init)CC_MD4_Init,
650 (hc_evp_md_update)CC_MD4_Update,
651 (hc_evp_md_final)CC_MD4_Final,
652 (hc_evp_md_cleanup)NULL
654 return &md4;
655 #elif HCRYPTO_FALLBACK
656 return EVP_hcrypto_md4();
657 #else
658 return NULL;
659 #endif
663 * The CommonCrypto md5 provider
665 * @ingroup hcrypto_evp
668 const EVP_MD *
669 EVP_cc_md5(void)
671 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
672 static const struct hc_evp_md md5 = {
673 CC_MD5_DIGEST_LENGTH,
674 CC_MD5_BLOCK_BYTES,
675 sizeof(CC_MD5_CTX),
676 (hc_evp_md_init)CC_MD5_Init,
677 (hc_evp_md_update)CC_MD5_Update,
678 (hc_evp_md_final)CC_MD5_Final,
679 (hc_evp_md_cleanup)NULL
681 return &md5;
682 #elif HCRYPTO_FALLBACK
683 return EVP_hcrypto_md5();
684 #else
685 return NULL;
686 #endif
690 * The CommonCrypto sha1 provider
692 * @ingroup hcrypto_evp
695 const EVP_MD *
696 EVP_cc_sha1(void)
698 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
699 static const struct hc_evp_md sha1 = {
700 CC_SHA1_DIGEST_LENGTH,
701 CC_SHA1_BLOCK_BYTES,
702 sizeof(CC_SHA1_CTX),
703 (hc_evp_md_init)CC_SHA1_Init,
704 (hc_evp_md_update)CC_SHA1_Update,
705 (hc_evp_md_final)CC_SHA1_Final,
706 (hc_evp_md_cleanup)NULL
708 return &sha1;
709 #elif HCRYPTO_FALLBACK
710 return EVP_hcrypto_sha1();
711 #else
712 return NULL;
713 #endif
717 * The CommonCrypto sha256 provider
719 * @ingroup hcrypto_evp
722 const EVP_MD *
723 EVP_cc_sha256(void)
725 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
726 static const struct hc_evp_md sha256 = {
727 CC_SHA256_DIGEST_LENGTH,
728 CC_SHA256_BLOCK_BYTES,
729 sizeof(CC_SHA256_CTX),
730 (hc_evp_md_init)CC_SHA256_Init,
731 (hc_evp_md_update)CC_SHA256_Update,
732 (hc_evp_md_final)CC_SHA256_Final,
733 (hc_evp_md_cleanup)NULL
735 return &sha256;
736 #elif HCRYPTO_FALLBACK
737 return EVP_hcrypto_sha256();
738 #else
739 return NULL;
740 #endif
744 * The CommonCrypto sha384 provider
746 * @ingroup hcrypto_evp
749 const EVP_MD *
750 EVP_cc_sha384(void)
752 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
753 static const struct hc_evp_md sha384 = {
754 CC_SHA384_DIGEST_LENGTH,
755 CC_SHA384_BLOCK_BYTES,
756 sizeof(CC_SHA512_CTX),
757 (hc_evp_md_init)CC_SHA384_Init,
758 (hc_evp_md_update)CC_SHA384_Update,
759 (hc_evp_md_final)CC_SHA384_Final,
760 (hc_evp_md_cleanup)NULL
762 return &sha384;
763 #elif HCRYPTO_FALLBACK
764 return EVP_hcrypto_sha384();
765 #else
766 return NULL;
767 #endif
771 * The CommonCrypto sha512 provider
773 * @ingroup hcrypto_evp
776 const EVP_MD *
777 EVP_cc_sha512(void)
779 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
780 static const struct hc_evp_md sha512 = {
781 CC_SHA512_DIGEST_LENGTH,
782 CC_SHA512_BLOCK_BYTES,
783 sizeof(CC_SHA512_CTX),
784 (hc_evp_md_init)CC_SHA512_Init,
785 (hc_evp_md_update)CC_SHA512_Update,
786 (hc_evp_md_final)CC_SHA512_Final,
787 (hc_evp_md_cleanup)NULL
789 return &sha512;
790 #elif HCRYPTO_FALLBACK
791 return EVP_hcrypto_sha512();
792 #else
793 return NULL;
794 #endif
798 * The Camellia-128 cipher type - CommonCrypto
800 * @return the Camellia-128 EVP_CIPHER pointer.
802 * @ingroup hcrypto_evp
805 const EVP_CIPHER *
806 EVP_cc_camellia_128_cbc(void)
808 #if HCRYPTO_FALLBACK
809 return EVP_hcrypto_camellia_128_cbc();
810 #else
811 return NULL;
812 #endif
816 * The Camellia-198 cipher type - CommonCrypto
818 * @return the Camellia-198 EVP_CIPHER pointer.
820 * @ingroup hcrypto_evp
823 const EVP_CIPHER *
824 EVP_cc_camellia_192_cbc(void)
826 #if HCRYPTO_FALLBACK
827 return EVP_hcrypto_camellia_192_cbc();
828 #else
829 return NULL;
830 #endif
834 * The Camellia-256 cipher type - CommonCrypto
836 * @return the Camellia-256 EVP_CIPHER pointer.
838 * @ingroup hcrypto_evp
841 const EVP_CIPHER *
842 EVP_cc_camellia_256_cbc(void)
844 #if HCRYPTO_FALLBACK
845 return EVP_hcrypto_camellia_256_cbc();
846 #else
847 return NULL;
848 #endif
851 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
857 static int
858 cc_rc4_init(EVP_CIPHER_CTX *ctx,
859 const unsigned char * key,
860 const unsigned char * iv,
861 int encp)
863 struct cc_key *cc = ctx->cipher_data;
864 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmRC4,
865 key, ctx->key_len, iv, &cc->href);
868 #endif
872 * The RC4 cipher type (Apple CommonCrypto provider)
874 * @return the RC4 EVP_CIPHER pointer.
876 * @ingroup hcrypto_evp
879 const EVP_CIPHER *
880 EVP_cc_rc4(void)
882 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
883 static const EVP_CIPHER rc4 = {
888 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
889 cc_rc4_init,
890 cc_do_cipher,
891 cc_cleanup,
892 sizeof(struct cc_key),
893 NULL,
894 NULL,
895 NULL,
896 NULL
898 return &rc4;
899 #elif HCRYPTO_FALLBACK
900 return EVP_hcrypto_rc4();
901 #else
902 return NULL;
903 #endif
908 * The RC4-40 cipher type (Apple CommonCrypto provider)
910 * @return the RC4 EVP_CIPHER pointer.
912 * @ingroup hcrypto_evp
915 const EVP_CIPHER *
916 EVP_cc_rc4_40(void)
918 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
919 static const EVP_CIPHER rc4_40 = {
924 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
925 cc_rc4_init,
926 cc_do_cipher,
927 cc_cleanup,
928 sizeof(struct cc_key),
929 NULL,
930 NULL,
931 NULL,
932 NULL
934 return &rc4_40;
935 #elif HCRYPTO_FALLBACK
936 return EVP_hcrypto_rc4_40();
937 #else
938 return NULL;
939 #endif
942 #endif /* __APPLE__ */