corecryptoSymmetricBridge.h [plain text]
#ifndef CommonCrypto_corecryptoSymmetricBridge_h
#define CommonCrypto_corecryptoSymmetricBridge_h
#include <stdbool.h>
#include <corecrypto/ccmode.h>
#include <corecrypto/ccmode_impl.h>
#include <corecrypto/ccaes.h>
#include <corecrypto/ccdes.h>
#include <corecrypto/cccast.h>
#include <corecrypto/ccrc2.h>
#include <corecrypto/ccblowfish.h>
#include <corecrypto/ccpad.h>
typedef union {
struct ccmode_ecb *ecb;
struct ccmode_cbc *cbc;
struct ccmode_cfb *cfb;
struct ccmode_cfb8 *cfb8;
struct ccmode_ctr *ctr;
struct ccmode_ofb *ofb;
struct ccmode_xts *xts;
struct ccmode_gcm *gcm;
} corecryptoMode;
typedef struct ccmode_ecb* (*ecb_p) (void);
typedef struct ccmode_cbc* (*cbc_p) (void);
typedef struct ccmode_cfb* (*cfb_p) (void);
typedef struct ccmode_cfb8* (*cfb8_p) (void);
typedef struct ccmode_ctr* (*ctr_p) (void);
typedef struct ccmode_ofb* (*ofb_p) (void);
typedef struct ccmode_xts* (*xts_p) (void);
typedef struct ccmode_gcm* (*gcm_p) (void);
typedef struct modes_t {
ecb_p ecb;
cbc_p cbc;
cfb_p cfb;
cfb8_p cfb8;
ctr_p ctr;
ofb_p ofb;
xts_p xts;
gcm_p gcm;
} modeList;
modeList ccmodeList[7][2];
typedef struct cbc_with_iv_t {
uint8_t iv[16];
cccbc_ctx cbc;
} cbc_iv_ctx;
typedef union {
void *data;
ccecb_ctx *ecb;
cbc_iv_ctx *cbc;
cccfb_ctx *cfb;
cccfb8_ctx *cfb8;
ccctr_ctx *ctr;
ccofb_ctx *ofb;
ccxts_ctx *xts;
ccgcm_ctx *gcm;
} modeCtx;
#pragma mark Modes
typedef void (*ccmode_setup_p)(corecryptoMode modeObj, const void *iv,
const void *key, size_t keylen, const void *tweak,
size_t tweaklen, int options, modeCtx ctx);
typedef void (*ccmode_encrypt_p)(corecryptoMode modeObj, const void *pt, void *ct, size_t len, modeCtx ctx);
typedef void (*ccmode_decrypt_p)(corecryptoMode modeObj, const void *ct, void *pt, size_t len, modeCtx ctx);
typedef void (*ccmode_encrypt_tweaked_p)(corecryptoMode modeObj, const void *pt, size_t len,
void *ct, const void *tweak, modeCtx ctx);
typedef void (*ccmode_decrypt_tweaked_p)(corecryptoMode modeObj, const void *ct, size_t len,
void *pt, const void *tweak, modeCtx ctx);
typedef int (*ccmode_done_p)(corecryptoMode modeObj, modeCtx ctx);
typedef int (*ccmode_setiv_p)(corecryptoMode modeObj, const void *iv, uint32_t len, modeCtx ctx);
typedef int (*ccmode_getiv_p)(corecryptoMode modeObj, void *iv, uint32_t *len, modeCtx ctx);
typedef size_t (*ccmode_get_ctx_size)(corecryptoMode modeObj);
typedef size_t (*ccmode_get_block_size)(corecryptoMode modeObj);
typedef struct cc2CCModeDescriptor_t {
ccmode_get_ctx_size mode_get_ctx_size;
ccmode_get_block_size mode_get_block_size;
ccmode_setup_p mode_setup;
ccmode_encrypt_p mode_encrypt;
ccmode_decrypt_p mode_decrypt;
ccmode_encrypt_tweaked_p mode_encrypt_tweaked;
ccmode_decrypt_tweaked_p mode_decrypt_tweaked;
ccmode_done_p mode_done;
ccmode_setiv_p mode_setiv;
ccmode_getiv_p mode_getiv;
} cc2CCModeDescriptor, *cc2CCModeDescriptorPtr;
cc2CCModeDescriptor ccecb_mode;
cc2CCModeDescriptor cccbc_mode;
cc2CCModeDescriptor cccfb_mode;
cc2CCModeDescriptor cccfb8_mode;
cc2CCModeDescriptor ccctr_mode;
cc2CCModeDescriptor ccofb_mode;
cc2CCModeDescriptor ccxts_mode;
cc2CCModeDescriptor ccgcm_mode;
typedef int (*cc_encrypt_pad_p)(modeCtx ctx, cc2CCModeDescriptorPtr modeptr, corecryptoMode modeObj, void *buff, uint32_t startpoint, void *cipherText, size_t *moved);
typedef int (*cc_decrypt_pad_p)(modeCtx ctx, cc2CCModeDescriptorPtr modeptr, corecryptoMode modeObj, void *buff, uint32_t startpoint, void *plainText, size_t *moved);
typedef size_t (*ccpadlen_p) (int encrypt, cc2CCModeDescriptorPtr modeptr, corecryptoMode modeObj, char *buffp);
typedef size_t (*ccreserve_p) (int encrypt, cc2CCModeDescriptorPtr modeptr, corecryptoMode modeObj);
typedef struct cc2CCPaddingDescriptor_t {
cc_encrypt_pad_p encrypt_pad;
cc_decrypt_pad_p decrypt_pad;
ccpadlen_p padlen;
ccreserve_p padreserve;
} cc2CCPaddingDescriptor, *cc2CCPaddingDescriptorPtr;
cc2CCPaddingDescriptor ccnopad_pad;
cc2CCPaddingDescriptor cccts1_pad;
cc2CCPaddingDescriptor cccts2_pad;
cc2CCPaddingDescriptor cccts3_pad;
cc2CCPaddingDescriptor ccpkcs7_pad;
cc2CCPaddingDescriptor ccpkcs7_ecb_pad;
#endif