]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/corecrypto/ccpad.h
xnu-3248.50.21.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / ccpad.h
CommitLineData
316670eb
A
1/*
2 * ccpad.h
3 * corecrypto
4 *
3e170ce0
A
5 * Created on 12/07/2010
6 *
7 * Copyright (c) 2010,2011,2012,2014,2015 Apple Inc. All rights reserved.
316670eb
A
8 *
9 */
10
11#ifndef _CORECRYPTO_CCPAD_H_
12#define _CORECRYPTO_CCPAD_H_
13
14#include <corecrypto/ccmode.h>
15
16/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
17void ccpad_cts_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
18 size_t nbytes, const void *in, void *out);
316670eb
A
19
20/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
21void ccpad_cts_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
22 size_t nbytes, const void *in, void *out);
316670eb
A
23
24/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
25void ccpad_cts1_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
26 size_t nbytes, const void *in, void *out);
316670eb
A
27
28/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
29void ccpad_cts1_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
30 size_t nbytes, const void *in, void *out);
316670eb 31/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
32void ccpad_cts2_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
33 size_t nbytes, const void *in, void *out);
316670eb
A
34
35/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
36void ccpad_cts2_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
37 size_t nbytes, const void *in, void *out);
316670eb 38/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
39void ccpad_cts3_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
40 size_t nbytes, const void *in, void *out);
316670eb
A
41
42/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
43void ccpad_cts3_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
44 size_t nbytes, const void *in, void *out);
316670eb
A
45
46/* 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.
47
48 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.
49 */
fe8ab488
A
50size_t ccpad_pkcs7_decrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
51 size_t nbytes, const void *in, void *out);
316670eb
A
52
53/* 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. */
fe8ab488
A
54void ccpad_pkcs7_encrypt(const struct ccmode_cbc *cbc, cccbc_ctx *ctx, cccbc_iv *iv,
55 size_t nbytes, const void *in, void *out);
56
57/* 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
58 crypt with an IV makes ecb cry (and crash) */
59
60size_t ccpad_pkcs7_ecb_decrypt(const struct ccmode_ecb *ecb, ccecb_ctx *ecb_key,
61 size_t nbytes, const void *in, void *out);
62
63void ccpad_pkcs7_ecb_encrypt(const struct ccmode_ecb *ecb, ccecb_ctx *ctx,
64 size_t nbytes, const void *in, void *out);
316670eb 65
3e170ce0
A
66/* Function common to ccpad_pkcs7_ecb_decrypt and ccpad_pkcs7_decrypt */
67size_t ccpad_pkcs7_decode(const size_t block_size, const uint8_t* last_block);
68
316670eb 69/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
70void ccpad_xts_decrypt(const struct ccmode_xts *xts, ccxts_ctx *ctx, ccxts_tweak *tweak,
71 size_t nbytes, const void *in, void *out);
316670eb
A
72
73/* Contract is nbytes is at least 1 block + 1 byte. Also in is nbytes long out is nbytes long. */
fe8ab488
A
74void ccpad_xts_encrypt(const struct ccmode_xts *xts, ccxts_ctx *ctx, ccxts_tweak *tweak,
75 size_t nbytes, const void *in, void *out);
316670eb
A
76
77#endif /* _CORECRYPTO_CCPAD_H_ */