]>
Commit | Line | Data |
---|---|---|
f427ee49 | 1 | /* Copyright (c) (2010,2011,2012,2014,2015,2019) Apple Inc. All rights reserved. |
316670eb | 2 | * |
f427ee49 A |
3 | * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which |
4 | * is contained in the License.txt file distributed with corecrypto) and only to | |
5 | * people who accept that license. IMPORTANT: Any license rights granted to you by | |
6 | * Apple Inc. (if any) are limited to internal use within your organization only on | |
7 | * devices and computers you own or control, for the sole purpose of verifying the | |
8 | * security characteristics and correct functioning of the Apple Software. You may | |
9 | * not, directly or indirectly, redistribute the Apple Software or any portions thereof. | |
316670eb A |
10 | */ |
11 | ||
12 | #ifndef _CORECRYPTO_CCPAD_H_ | |
13 | #define _CORECRYPTO_CCPAD_H_ | |
14 | ||
15 | #include <corecrypto/ccmode.h> | |
16 | ||
39037602 A |
17 | // CTS1,2,3 are defined in Addendum to 800-38A, |
18 | // "Cipher Modes of Operation: Three Variants of Ciphertext Stealing for CBC Mode" | |
19 | // CTS3 is also known as "CTS" in RFC3962 | |
316670eb A |
20 | |
21 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ | |
39037602 | 22 | size_t ccpad_cts1_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 23 | size_t nbytes, const void *in, void *out); |
316670eb A |
24 | |
25 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ | |
39037602 | 26 | size_t ccpad_cts1_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 27 | size_t nbytes, const void *in, void *out); |
316670eb | 28 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ |
39037602 | 29 | size_t ccpad_cts2_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 30 | size_t nbytes, const void *in, void *out); |
316670eb A |
31 | |
32 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ | |
39037602 | 33 | size_t ccpad_cts2_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 34 | size_t nbytes, const void *in, void *out); |
316670eb | 35 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ |
39037602 | 36 | size_t ccpad_cts3_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 37 | size_t nbytes, const void *in, void *out); |
316670eb A |
38 | |
39 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ | |
39037602 | 40 | size_t ccpad_cts3_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 | 41 | size_t nbytes, const void *in, void *out); |
316670eb A |
42 | |
43 | /* Contract is nbytes is non zero and a multiple of block_size. Furthermore in is nbytes long and out is nbytes long. Returns number of bytes written to out (technically we always write nbytes to out but the returned value is the number of bytes decrypted after removal of padding. | |
44 | ||
45 | To be safe we remove the entire offending block if the pkcs7 padding checks failed. However we purposely don't report the failure to decode the padding since any use of this error leads to potential security exploits. So currently there is no way to distinguish between a full block of padding and bad padding. | |
46 | */ | |
fe8ab488 A |
47 | size_t ccpad_pkcs7_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
48 | size_t nbytes, const void *in, void *out); | |
316670eb A |
49 | |
50 | /* Contract is in is nbytes long. Writes (nbytes / block_size) + 1 times block_size to out. In other words, out must be nbytes rounded down to the closest multiple of block_size plus block_size bytes. */ | |
39037602 | 51 | size_t ccpad_pkcs7_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv, |
fe8ab488 A |
52 | size_t nbytes, const void *in, void *out); |
53 | ||
54 | /* Contract is 'don't break CommonCrypto functionality that allows PKCS7 padding with ECB mode'. This is basically the same routines above, without an IV, because calling | |
55 | crypt with an IV makes ecb cry (and crash) */ | |
56 | ||
57 | size_t ccpad_pkcs7_ecb_decrypt(const struct ccmode_ecb *ecb, ccecb_ctx *ecb_key, | |
58 | size_t nbytes, const void *in, void *out); | |
59 | ||
39037602 | 60 | size_t ccpad_pkcs7_ecb_encrypt(const struct ccmode_ecb *ecb, ccecb_ctx *ctx, |
fe8ab488 | 61 | size_t nbytes, const void *in, void *out); |
316670eb | 62 | |
3e170ce0 A |
63 | /* Function common to ccpad_pkcs7_ecb_decrypt and ccpad_pkcs7_decrypt */ |
64 | size_t ccpad_pkcs7_decode(const size_t block_size, const uint8_t* last_block); | |
65 | ||
316670eb | 66 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ |
39037602 | 67 | size_t ccpad_xts_decrypt(const struct ccmode_xts *xts, ccxts_ctx *ctx, ccxts_tweak *tweak, |
fe8ab488 | 68 | size_t nbytes, const void *in, void *out); |
316670eb A |
69 | |
70 | /* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */ | |
fe8ab488 A |
71 | void ccpad_xts_encrypt(const struct ccmode_xts *xts, ccxts_ctx *ctx, ccxts_tweak *tweak, |
72 | size_t nbytes, const void *in, void *out); | |
316670eb A |
73 | |
74 | #endif /* _CORECRYPTO_CCPAD_H_ */ |