Debian Codegraph @

lib/hcrypto/evp-cc.c

raw
1 /*
2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
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.
18 *
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.
22 *
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.
34 */
35
36 /* CommonCrypto provider */
37
38 #ifdef __APPLE__
39
40 #include <config.h>
41 #include <roken.h>
42
43 #include <assert.h>
44
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
51
52 #include <evp.h>
53 #include <evp-hcrypto.h>
54 #include <evp-cc.h>
55
56 /*
57 *
58 */
59
60 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
61
62 struct cc_key {
63 CCCryptorRef href;
64 };
65
66 static int
67 cc_do_cipher(EVP_CIPHER_CTX *ctx,
68 unsigned char *out,
69 const unsigned char *in,
70 unsigned int size)
71 {
72 struct cc_key *cc = ctx->cipher_data;
73 CCCryptorStatus ret;
74 size_t moved;
75
76 memcpy(out, in, size);
77
78 ret = CCCryptorUpdate(cc->href, in, size, out, size, &moved);
79 if (ret)
80 return 0;
81
82 if (moved != size)
83 return 0;
84
85 return 1;
86 }
87
88 static int
89 cc_cleanup(EVP_CIPHER_CTX *ctx)
90 {
91 struct cc_key *cc = ctx->cipher_data;
92 if (cc->href)
93 CCCryptorRelease(cc->href);
94 return 1;
95 }
96
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)
101 {
102 CCOperation op = encp ? kCCEncrypt : kCCDecrypt;
103 CCMode mode;
104 CCModeOptions options = 0;
105 CCCryptorStatus ret;
106
107 if (*ref) {
108 if (key == NULL && iv) {
109 CCCryptorReset(*ref, iv);
110 return 1;
111 }
112 CCCryptorRelease(*ref);
113 }
114
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;
126 }
127
128 ret = CCCryptorCreateWithMode(op, mode, alg, ccNoPadding,
129 iv, key, keylen, NULL, 0, 0,
130 options, ref);
131 if (ret)
132 return 0;
133 }
134
135 return 1;
136 }
137
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)
143 {
144 struct cc_key *cc = ctx->cipher_data;
145 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithm3DES,
146 key, kCCKeySize3DES, iv, &cc->href);
147 }
148
149 #endif /* HAVE_COMMONCRYPTO_COMMONCRYPTOR_H */
150
151 /**
152 * The triple DES cipher type (Apple CommonCrypto provider)
153 *
154 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
155 *
156 * @ingroup hcrypto_evp
157 */
158
159 const EVP_CIPHER *
160 EVP_cc_des_ede3_cbc(void)
161 {
162 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
163 static const EVP_CIPHER des_ede3_cbc = {
164 0,
165 8,
166 24,
167 8,
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
177 };
178 return &des_ede3_cbc;
179 #elif HCRYPTO_FALLBACK
180 return EVP_hcrypto_des_ede3_cbc();
181 #else
182 return NULL;
183 #endif
184 }
185
186 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
187 /*
188 *
189 */
190
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)
196 {
197 struct cc_key *cc = ctx->cipher_data;
198 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmDES,
199 key, kCCBlockSizeDES, iv, &cc->href);
200 }
201 #endif
202
203 /**
204 * The DES cipher type (Apple CommonCrypto provider)
205 *
206 * @return the DES-CBC EVP_CIPHER pointer.
207 *
208 * @ingroup hcrypto_evp
209 */
210
211 const EVP_CIPHER *
212 EVP_cc_des_cbc(void)
213 {
214 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
215 static const EVP_CIPHER des_ede3_cbc = {
216 0,
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
229 };
230 return &des_ede3_cbc;
231 #elif HCRYPTO_FALLBACK
232 return EVP_hcrypto_des_cbc();
233 #else
234 return NULL;
235 #endif
236 }
237
238 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
239 /*
240 *
241 */
242
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)
248 {
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);
252 }
253 #endif
254
255 /**
256 * The AES-128 cipher type (Apple CommonCrypto provider)
257 *
258 * @return the AES-128-CBC EVP_CIPHER pointer.
259 *
260 * @ingroup hcrypto_evp
261 */
262
263 const EVP_CIPHER *
264 EVP_cc_aes_128_cbc(void)
265 {
266 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
267 static const EVP_CIPHER c = {
268 0,
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
281 };
282 return &c;
283 #elif HCRYPTO_FALLBACK
284 return EVP_hcrypto_aes_128_cbc();
285 #else
286 return NULL;
287 #endif
288 }
289
290 /**
291 * The AES-192 cipher type (Apple CommonCrypto provider)
292 *
293 * @return the AES-192-CBC EVP_CIPHER pointer.
294 *
295 * @ingroup hcrypto_evp
296 */
297
298 const EVP_CIPHER *
299 EVP_cc_aes_192_cbc(void)
300 {
301 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
302 static const EVP_CIPHER c = {
303 0,
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
316 };
317 return &c;
318 #elif HCRYPTO_FALLBACK
319 return EVP_hcrypto_aes_192_cbc();
320 #else
321 return NULL;
322 #endif
323 }
324
325 /**
326 * The AES-256 cipher type (Apple CommonCrypto provider)
327 *
328 * @return the AES-256-CBC EVP_CIPHER pointer.
329 *
330 * @ingroup hcrypto_evp
331 */
332
333 const EVP_CIPHER *
334 EVP_cc_aes_256_cbc(void)
335 {
336 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
337 static const EVP_CIPHER c = {
338 0,
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
351 };
352 return &c;
353 #elif HCRYPTO_FALLBACK
354 return EVP_hcrypto_aes_256_cbc();
355 #else
356 return NULL;
357 #endif
358 }
359
360 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
361 /*
362 *
363 */
364
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)
370 {
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);
374 }
375 #endif
376
377 /**
378 * The AES-128 CFB8 cipher type (Apple CommonCrypto provider)
379 *
380 * @return the AES-128-CFB8 EVP_CIPHER pointer.
381 *
382 * @ingroup hcrypto_evp
383 */
384
385 const EVP_CIPHER *
386 EVP_cc_aes_128_cfb8(void)
387 {
388 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
389 static const EVP_CIPHER c = {
390 0,
391 1,
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
403 };
404 return &c;
405 #elif HCRYPTO_FALLBACK
406 return EVP_hcrypto_aes_128_cfb8();
407 #else
408 return NULL;
409 #endif
410 }
411
412 /**
413 * The AES-192 CFB8 cipher type (Apple CommonCrypto provider)
414 *
415 * @return the AES-192-CFB8 EVP_CIPHER pointer.
416 *
417 * @ingroup hcrypto_evp
418 */
419
420 const EVP_CIPHER *
421 EVP_cc_aes_192_cfb8(void)
422 {
423 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
424 static const EVP_CIPHER c = {
425 0,
426 1,
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
438 };
439 return &c;
440 #elif HCRYPTO_FALLBACK
441 return EVP_hcrypto_aes_192_cfb8();
442 #else
443 return NULL;
444 #endif
445 }
446
447 /**
448 * The AES-256 CFB8 cipher type (Apple CommonCrypto provider)
449 *
450 * @return the AES-256-CFB8 EVP_CIPHER pointer.
451 *
452 * @ingroup hcrypto_evp
453 */
454
455 const EVP_CIPHER *
456 EVP_cc_aes_256_cfb8(void)
457 {
458 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
459 static const EVP_CIPHER c = {
460 0,
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
473 };
474 return &c;
475 #elif HCRYPTO_FALLBACK
476 return EVP_hcrypto_aes_256_cfb8();
477 #else
478 return NULL;
479 #endif
480 }
481
482 /*
483 *
484 */
485
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)
492 {
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);
496 }
497 #endif
498
499 /**
500 * The RC2 cipher type - common crypto
501 *
502 * @return the RC2 EVP_CIPHER pointer.
503 *
504 * @ingroup hcrypto_evp
505 */
506
507
508 const EVP_CIPHER *
509 EVP_cc_rc2_cbc(void)
510 {
511 #ifdef COMMONCRYPTO_SUPPORTS_RC2
512 static const EVP_CIPHER rc2_cbc = {
513 0,
514 kCCBlockSizeRC2,
515 16,
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
526 };
527 return &rc2_cbc;
528 #elif HCRYPTO_FALLBACK
529 return EVP_hcrypto_rc2_cbc();
530 #else
531 return NULL;
532 #endif
533 }
534
535 /**
536 * The RC2-40 cipher type - common crypto
537 *
538 * @return the RC2-40 EVP_CIPHER pointer.
539 *
540 * @ingroup hcrypto_evp
541 */
542
543
544 const EVP_CIPHER *
545 EVP_cc_rc2_40_cbc(void)
546 {
547 #ifdef COMMONCRYPTO_SUPPORTS_RC2
548 static const EVP_CIPHER rc2_40_cbc = {
549 0,
550 kCCBlockSizeRC2,
551 5,
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
562 };
563 return &rc2_40_cbc;
564 #elif HCRYPTO_FALLBACK
565 return EVP_hcrypto_rc2_40_cbc();
566 #else
567 return NULL;
568 #endif
569 }
570
571
572 /**
573 * The RC2-64 cipher type - common crypto
574 *
575 * @return the RC2-64 EVP_CIPHER pointer.
576 *
577 * @ingroup hcrypto_evp
578 */
579
580
581 const EVP_CIPHER *
582 EVP_cc_rc2_64_cbc(void)
583 {
584 #ifdef COMMONCRYPTO_SUPPORTS_RC2
585 static const EVP_CIPHER rc2_64_cbc = {
586 0,
587 kCCBlockSizeRC2,
588 8,
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
599 };
600 return &rc2_64_cbc;
601 #elif HCRYPTO_FALLBACK
602 return EVP_hcrypto_rc2_64_cbc();
603 #else
604 return NULL;
605 #endif
606 }
607
608
609 /**
610 * The CommonCrypto md4 provider
611 *
612 * @ingroup hcrypto_evp
613 */
614
615 const EVP_MD *
616 EVP_cc_md4(void)
617 {
618 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
619 static const struct hc_evp_md md4 = {
620 CC_MD4_DIGEST_LENGTH,
621 CC_MD4_BLOCK_BYTES,
622 sizeof(CC_MD4_CTX),
623 (hc_evp_md_init)CC_MD4_Init,
624 (hc_evp_md_update)CC_MD4_Update,
625 (hc_evp_md_final)CC_MD4_Final,
626 (hc_evp_md_cleanup)NULL
627 };
628 return &md4;
629 #elif HCRYPTO_FALLBACK
630 return EVP_hcrypto_md4();
631 #else
632 return NULL;
633 #endif
634 }
635
636 /**
637 * The CommonCrypto md5 provider
638 *
639 * @ingroup hcrypto_evp
640 */
641
642 const EVP_MD *
643 EVP_cc_md5(void)
644 {
645 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
646 static const struct hc_evp_md md5 = {
647 CC_MD5_DIGEST_LENGTH,
648 CC_MD5_BLOCK_BYTES,
649 sizeof(CC_MD5_CTX),
650 (hc_evp_md_init)CC_MD5_Init,
651 (hc_evp_md_update)CC_MD5_Update,
652 (hc_evp_md_final)CC_MD5_Final,
653 (hc_evp_md_cleanup)NULL
654 };
655 return &md5;
656 #elif HCRYPTO_FALLBACK
657 return EVP_hcrypto_md5();
658 #else
659 return NULL;
660 #endif
661 }
662
663 /**
664 * The CommonCrypto sha1 provider
665 *
666 * @ingroup hcrypto_evp
667 */
668
669 const EVP_MD *
670 EVP_cc_sha1(void)
671 {
672 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
673 static const struct hc_evp_md sha1 = {
674 CC_SHA1_DIGEST_LENGTH,
675 CC_SHA1_BLOCK_BYTES,
676 sizeof(CC_SHA1_CTX),
677 (hc_evp_md_init)CC_SHA1_Init,
678 (hc_evp_md_update)CC_SHA1_Update,
679 (hc_evp_md_final)CC_SHA1_Final,
680 (hc_evp_md_cleanup)NULL
681 };
682 return &sha1;
683 #elif HCRYPTO_FALLBACK
684 return EVP_hcrypto_sha1();
685 #else
686 return NULL;
687 #endif
688 }
689
690 /**
691 * The CommonCrypto sha256 provider
692 *
693 * @ingroup hcrypto_evp
694 */
695
696 const EVP_MD *
697 EVP_cc_sha256(void)
698 {
699 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
700 static const struct hc_evp_md sha256 = {
701 CC_SHA256_DIGEST_LENGTH,
702 CC_SHA256_BLOCK_BYTES,
703 sizeof(CC_SHA256_CTX),
704 (hc_evp_md_init)CC_SHA256_Init,
705 (hc_evp_md_update)CC_SHA256_Update,
706 (hc_evp_md_final)CC_SHA256_Final,
707 (hc_evp_md_cleanup)NULL
708 };
709 return &sha256;
710 #elif HCRYPTO_FALLBACK
711 return EVP_hcrypto_sha256();
712 #else
713 return NULL;
714 #endif
715 }
716
717 /**
718 * The CommonCrypto sha384 provider
719 *
720 * @ingroup hcrypto_evp
721 */
722
723 const EVP_MD *
724 EVP_cc_sha384(void)
725 {
726 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
727 static const struct hc_evp_md sha384 = {
728 CC_SHA384_DIGEST_LENGTH,
729 CC_SHA384_BLOCK_BYTES,
730 sizeof(CC_SHA512_CTX),
731 (hc_evp_md_init)CC_SHA384_Init,
732 (hc_evp_md_update)CC_SHA384_Update,
733 (hc_evp_md_final)CC_SHA384_Final,
734 (hc_evp_md_cleanup)NULL
735 };
736 return &sha384;
737 #elif HCRYPTO_FALLBACK
738 return EVP_hcrypto_sha384();
739 #else
740 return NULL;
741 #endif
742 }
743
744 /**
745 * The CommonCrypto sha512 provider
746 *
747 * @ingroup hcrypto_evp
748 */
749
750 const EVP_MD *
751 EVP_cc_sha512(void)
752 {
753 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
754 static const struct hc_evp_md sha512 = {
755 CC_SHA512_DIGEST_LENGTH,
756 CC_SHA512_BLOCK_BYTES,
757 sizeof(CC_SHA512_CTX),
758 (hc_evp_md_init)CC_SHA512_Init,
759 (hc_evp_md_update)CC_SHA512_Update,
760 (hc_evp_md_final)CC_SHA512_Final,
761 (hc_evp_md_cleanup)NULL
762 };
763 return &sha512;
764 #elif HCRYPTO_FALLBACK
765 return EVP_hcrypto_sha512();
766 #else
767 return NULL;
768 #endif
769 }
770
771 /**
772 * The Camellia-128 cipher type - CommonCrypto
773 *
774 * @return the Camellia-128 EVP_CIPHER pointer.
775 *
776 * @ingroup hcrypto_evp
777 */
778
779 const EVP_CIPHER *
780 EVP_cc_camellia_128_cbc(void)
781 {
782 #if HCRYPTO_FALLBACK
783 return EVP_hcrypto_camellia_128_cbc();
784 #else
785 return NULL;
786 #endif
787 }
788
789 /**
790 * The Camellia-198 cipher type - CommonCrypto
791 *
792 * @return the Camellia-198 EVP_CIPHER pointer.
793 *
794 * @ingroup hcrypto_evp
795 */
796
797 const EVP_CIPHER *
798 EVP_cc_camellia_192_cbc(void)
799 {
800 #if HCRYPTO_FALLBACK
801 return EVP_hcrypto_camellia_192_cbc();
802 #else
803 return NULL;
804 #endif
805 }
806
807 /**
808 * The Camellia-256 cipher type - CommonCrypto
809 *
810 * @return the Camellia-256 EVP_CIPHER pointer.
811 *
812 * @ingroup hcrypto_evp
813 */
814
815 const EVP_CIPHER *
816 EVP_cc_camellia_256_cbc(void)
817 {
818 #if HCRYPTO_FALLBACK
819 return EVP_hcrypto_camellia_256_cbc();
820 #else
821 return NULL;
822 #endif
823 }
824
825 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
826
827 /*
828 *
829 */
830
831 static int
832 cc_rc4_init(EVP_CIPHER_CTX *ctx,
833 const unsigned char * key,
834 const unsigned char * iv,
835 int encp)
836 {
837 struct cc_key *cc = ctx->cipher_data;
838 return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmRC4,
839 key, ctx->key_len, iv, &cc->href);
840 }
841
842 #endif
843
844 /**
845
846 * The RC4 cipher type (Apple CommonCrypto provider)
847 *
848 * @return the RC4 EVP_CIPHER pointer.
849 *
850 * @ingroup hcrypto_evp
851 */
852
853 const EVP_CIPHER *
854 EVP_cc_rc4(void)
855 {
856 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
857 static const EVP_CIPHER rc4 = {
858 0,
859 1,
860 16,
861 0,
862 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
863 cc_rc4_init,
864 cc_do_cipher,
865 cc_cleanup,
866 sizeof(struct cc_key),
867 NULL,
868 NULL,
869 NULL,
870 NULL
871 };
872 return &rc4;
873 #elif HCRYPTO_FALLBACK
874 return EVP_hcrypto_rc4();
875 #else
876 return NULL;
877 #endif
878 }
879
880
881 /**
882 * The RC4-40 cipher type (Apple CommonCrypto provider)
883 *
884 * @return the RC4 EVP_CIPHER pointer.
885 *
886 * @ingroup hcrypto_evp
887 */
888
889 const EVP_CIPHER *
890 EVP_cc_rc4_40(void)
891 {
892 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
893 static const EVP_CIPHER rc4_40 = {
894 0,
895 1,
896 5,
897 0,
898 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
899 cc_rc4_init,
900 cc_do_cipher,
901 cc_cleanup,
902 sizeof(struct cc_key),
903 NULL,
904 NULL,
905 NULL,
906 NULL
907 };
908 return &rc4_40;
909 #elif HCRYPTO_FALLBACK
910 return EVP_hcrypto_rc4_40();
911 #else
912 return NULL;
913 #endif
914 }
915
916 #endif /* __APPLE__ */
917