2 * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _CRYPTO_REGISTER_CRYPTO_H_
30 #define _CRYPTO_REGISTER_CRYPTO_H_
36 #include <corecrypto/ccdigest.h>
37 #include <corecrypto/cchmac.h>
38 #include <corecrypto/ccmode.h>
39 #include <corecrypto/ccrc4.h>
40 #include <corecrypto/ccrng.h>
41 #include <corecrypto/ccrsa.h>
46 typedef void (*ccdigest_init_fn_t
)(const struct ccdigest_info
*di
, ccdigest_ctx_t ctx
);
47 typedef void (*ccdigest_update_fn_t
)(const struct ccdigest_info
*di
, ccdigest_ctx_t ctx
,
48 unsigned long len
, const void *data
);
49 typedef void (*ccdigest_final_fn_t
)(const struct ccdigest_info
*di
, ccdigest_ctx_t ctx
,
51 typedef void (*ccdigest_fn_t
)(const struct ccdigest_info
*di
, unsigned long len
,
52 const void *data
, void *digest
);
55 typedef void (*cchmac_init_fn_t
)(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
56 unsigned long key_len
, const void *key
);
57 typedef void (*cchmac_update_fn_t
)(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
58 unsigned long data_len
, const void *data
);
59 typedef void (*cchmac_final_fn_t
)(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
62 typedef void (*cchmac_fn_t
)(const struct ccdigest_info
*di
, unsigned long key_len
,
63 const void *key
, unsigned long data_len
, const void *data
,
67 typedef int (*ccgcm_init_with_iv_fn_t
)(const struct ccmode_gcm
*mode
, ccgcm_ctx
*ctx
,
68 size_t key_nbytes
, const void *key
,
70 typedef int (*ccgcm_inc_iv_fn_t
)(const struct ccmode_gcm
*mode
, ccgcm_ctx
*ctx
, void *iv
);
74 typedef void (*ccpbkdf2_hmac_fn_t
)(const struct ccdigest_info
*di
,
75 unsigned long passwordLen
, const void *password
,
76 unsigned long saltLen
, const void *salt
,
77 unsigned long iterations
,
78 unsigned long dkLen
, void *dk
);
80 /* des weak key testing */
81 typedef int (*ccdes_key_is_weak_fn_t
)(void *key
, unsigned long length
);
82 typedef void (*ccdes_key_set_odd_parity_fn_t
)(void *key
, unsigned long length
);
85 typedef void (*ccpad_xts_decrypt_fn_t
)(const struct ccmode_xts
*xts
, ccxts_ctx
*ctx
,
86 unsigned long nbytes
, const void *in
, void *out
);
88 typedef void (*ccpad_xts_encrypt_fn_t
)(const struct ccmode_xts
*xts
, ccxts_ctx
*ctx
,
89 unsigned long nbytes
, const void *in
, void *out
);
91 /* CBC padding (such as PKCS7 or CTSx per NIST standard) */
92 typedef size_t (*ccpad_cts3_crypt_fn_t
)(const struct ccmode_cbc
*cbc
, cccbc_ctx
*cbc_key
,
93 cccbc_iv
*iv
, size_t nbytes
, const void *in
, void *out
);
96 typedef struct ccrng_state
*(*ccrng_fn_t
)(int *error
);
99 typedef int (*ccrsa_make_pub_fn_t
)(ccrsa_pub_ctx_t pubk
,
100 size_t exp_nbytes
, const uint8_t *exp
,
101 size_t mod_nbytes
, const uint8_t *mod
);
103 typedef int (*ccrsa_verify_pkcs1v15_fn_t
)(ccrsa_pub_ctx_t key
, const uint8_t *oid
,
104 size_t digest_len
, const uint8_t *digest
,
105 size_t sig_len
, const uint8_t *sig
,
108 typedef struct crypto_functions
{
109 /* digests common functions */
110 ccdigest_init_fn_t ccdigest_init_fn
;
111 ccdigest_update_fn_t ccdigest_update_fn
;
112 ccdigest_final_fn_t ccdigest_final_fn
;
113 ccdigest_fn_t ccdigest_fn
;
114 /* digest implementations */
115 const struct ccdigest_info
* ccmd5_di
;
116 const struct ccdigest_info
* ccsha1_di
;
117 const struct ccdigest_info
* ccsha256_di
;
118 const struct ccdigest_info
* ccsha384_di
;
119 const struct ccdigest_info
* ccsha512_di
;
121 /* hmac common function */
122 cchmac_init_fn_t cchmac_init_fn
;
123 cchmac_update_fn_t cchmac_update_fn
;
124 cchmac_final_fn_t cchmac_final_fn
;
125 cchmac_fn_t cchmac_fn
;
127 /* ciphers modes implementations */
128 /* AES, ecb, cbc and xts */
129 const struct ccmode_ecb
*ccaes_ecb_encrypt
;
130 const struct ccmode_ecb
*ccaes_ecb_decrypt
;
131 const struct ccmode_cbc
*ccaes_cbc_encrypt
;
132 const struct ccmode_cbc
*ccaes_cbc_decrypt
;
133 const struct ccmode_xts
*ccaes_xts_encrypt
;
134 const struct ccmode_xts
*ccaes_xts_decrypt
;
135 const struct ccmode_gcm
*ccaes_gcm_encrypt
;
136 const struct ccmode_gcm
*ccaes_gcm_decrypt
;
138 ccgcm_init_with_iv_fn_t ccgcm_init_with_iv_fn
;
139 ccgcm_inc_iv_fn_t ccgcm_inc_iv_fn
;
141 /* DES, ecb and cbc */
142 const struct ccmode_ecb
*ccdes_ecb_encrypt
;
143 const struct ccmode_ecb
*ccdes_ecb_decrypt
;
144 const struct ccmode_cbc
*ccdes_cbc_encrypt
;
145 const struct ccmode_cbc
*ccdes_cbc_decrypt
;
146 /* Triple DES, ecb and cbc */
147 const struct ccmode_ecb
*cctdes_ecb_encrypt
;
148 const struct ccmode_ecb
*cctdes_ecb_decrypt
;
149 const struct ccmode_cbc
*cctdes_cbc_encrypt
;
150 const struct ccmode_cbc
*cctdes_cbc_decrypt
;
152 const struct ccrc4_info
*ccrc4_info
;
153 /* Blowfish - ECB only */
154 const struct ccmode_ecb
*ccblowfish_ecb_encrypt
;
155 const struct ccmode_ecb
*ccblowfish_ecb_decrypt
;
156 /* CAST - ECB only */
157 const struct ccmode_ecb
*cccast_ecb_encrypt
;
158 const struct ccmode_ecb
*cccast_ecb_decrypt
;
159 /* DES key helper functions */
160 ccdes_key_is_weak_fn_t ccdes_key_is_weak_fn
;
161 ccdes_key_set_odd_parity_fn_t ccdes_key_set_odd_parity_fn
;
162 /* XTS padding+encrypt functions */
163 ccpad_xts_encrypt_fn_t ccpad_xts_encrypt_fn
;
164 ccpad_xts_decrypt_fn_t ccpad_xts_decrypt_fn
;
165 /* CTS3 padding+encrypt functions */
166 ccpad_cts3_crypt_fn_t ccpad_cts3_encrypt_fn
;
167 ccpad_cts3_crypt_fn_t ccpad_cts3_decrypt_fn
;
173 ccrsa_make_pub_fn_t ccrsa_make_pub_fn
;
174 ccrsa_verify_pkcs1v15_fn_t ccrsa_verify_pkcs1v15_fn
;
175 } *crypto_functions_t
;
177 int register_crypto_functions(const crypto_functions_t funcs
);
183 #endif /*_CRYPTO_REGISTER_CRYPTO_H_*/