-void ccmode_cbc_init(const struct ccmode_cbc *cbc, cccbc_ctx *ctx,
- size_t rawkey_len, const void *rawkey);
-void ccmode_cbc_decrypt(const cccbc_ctx *ctx, cccbc_iv *iv, size_t nblocks,
- const void *in, void *out);
-void ccmode_cbc_encrypt(const cccbc_ctx *ctx, cccbc_iv *iv, size_t nblocks,
- const void *in, void *out);
+int ccmode_cbc_init(const struct ccmode_cbc *cbc, cccbc_ctx *ctx,
+ size_t rawkey_len, const void *rawkey);
+int ccmode_cbc_decrypt(const cccbc_ctx *ctx, cccbc_iv *iv, size_t nblocks,
+ const void *in, void *out);
+int ccmode_cbc_encrypt(const cccbc_ctx *ctx, cccbc_iv *iv, size_t nblocks,
+ const void *in, void *out);
struct _ccmode_cbc_key {
const struct ccmode_ecb *ecb;
const struct ccmode_ecb *ecb);
-void ccmode_cfb_init(const struct ccmode_cfb *cfb, cccfb_ctx *ctx,
- size_t rawkey_len, const void *rawkey,
- const void *iv);
-void ccmode_cfb_decrypt(cccfb_ctx *ctx, size_t nbytes,
- const void *in, void *out);
-void ccmode_cfb_encrypt(cccfb_ctx *ctx, size_t nbytes,
- const void *in, void *out);
+int ccmode_cfb_init(const struct ccmode_cfb *cfb, cccfb_ctx *ctx,
+ size_t rawkey_len, const void *rawkey,
+ const void *iv);
+int ccmode_cfb_decrypt(cccfb_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
+int ccmode_cfb_encrypt(cccfb_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
struct _ccmode_cfb_key {
const struct ccmode_ecb *ecb;
size_t pad_len;
void ccmode_factory_cfb_encrypt(struct ccmode_cfb *cfb,
const struct ccmode_ecb *ecb);
-void ccmode_cfb8_init(const struct ccmode_cfb8 *cfb8, cccfb8_ctx *ctx,
- size_t rawkey_len, const void *rawkey, const void *iv);
-void ccmode_cfb8_decrypt(cccfb8_ctx *ctx, size_t nbytes,
- const void *in, void *out);
-void ccmode_cfb8_encrypt(cccfb8_ctx *ctx, size_t nbytes,
- const void *in, void *out);
+int ccmode_cfb8_init(const struct ccmode_cfb8 *cfb8, cccfb8_ctx *ctx,
+ size_t rawkey_len, const void *rawkey, const void *iv);
+int ccmode_cfb8_decrypt(cccfb8_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
+int ccmode_cfb8_encrypt(cccfb8_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
struct _ccmode_cfb8_key {
const struct ccmode_ecb *ecb;
void ccmode_factory_cfb8_encrypt(struct ccmode_cfb8 *cfb8,
const struct ccmode_ecb *ecb);
-void ccmode_ctr_init(const struct ccmode_ctr *ctr, ccctr_ctx *ctx,
- size_t rawkey_len, const void *rawkey, const void *iv);
-void ccmode_ctr_crypt(ccctr_ctx *ctx, size_t nbytes,
- const void *in, void *out);
+int ccmode_ctr_init(const struct ccmode_ctr *ctr, ccctr_ctx *ctx,
+ size_t rawkey_len, const void *rawkey, const void *iv);
+int ccmode_ctr_crypt(ccctr_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
struct _ccmode_ctr_key {
const struct ccmode_ecb *ecb;
storage. */
int ccmode_gcm_init(const struct ccmode_gcm *gcm, ccgcm_ctx *ctx,
size_t rawkey_len, const void *rawkey);
-int ccmode_gcm_set_iv(ccgcm_ctx *ctx, size_t iv_size, const void *iv);
+int ccmode_gcm_set_iv(ccgcm_ctx *ctx, size_t iv_nbytes, const void *iv);
int ccmode_gcm_aad(ccgcm_ctx *ctx, size_t nbytes, const void *in);
int ccmode_gcm_decrypt(ccgcm_ctx *ctx, size_t nbytes, const void *in,
void *out);
int ccmode_gcm_finalize(ccgcm_ctx *key, size_t tag_size, void *tag);
int ccmode_gcm_reset(ccgcm_ctx *key);
+#define CCGCM_FLAGS_INIT_WITH_IV 1
// Here is what the structure looks like in memory
// [ temp space | length | *ecb | *ecb_key | table | ecb_key ]
// size of table depends on the implementation (VNG vs factory)
+// currently, VNG and factory share the same "header" described here
+// VNG may add additional data after the header
struct _ccmode_gcm_key {
// 5 blocks of temp space.
unsigned char H[16]; /* multiplier */
unsigned char buf[16]; /* buffer for stuff */
// State and length
- uint32_t ivmode; /* Which mode is the IV in? */
- uint32_t state; /* state the GCM code is in */
- uint32_t buflen; /* length of data in buf */
+ uint16_t state; /* state the GCM code is in */
+ uint16_t flags; /* flags (persistent across reset) */
+ uint32_t buf_nbytes; /* length of data in buf */
- uint64_t totlen; /* 64-bit counter used for IV and AAD */
- uint64_t pttotlen; /* 64-bit counter for the plaintext PT */
+ uint64_t aad_nbytes; /* 64-bit counter used for IV and AAD */
+ uint64_t text_nbytes; /* 64-bit counter for the plaintext PT */
// ECB
const struct ccmode_ecb *ecb; // ecb mode
const struct ccmode_ecb *ecb_encrypt);
-void ccmode_ofb_init(const struct ccmode_ofb *ofb, ccofb_ctx *ctx,
- size_t rawkey_len, const void *rawkey,
- const void *iv);
-void ccmode_ofb_crypt(ccofb_ctx *ctx, size_t nbytes,
- const void *in, void *out);
+int ccmode_ofb_init(const struct ccmode_ofb *ofb, ccofb_ctx *ctx,
+ size_t rawkey_len, const void *rawkey,
+ const void *iv);
+int ccmode_ofb_crypt(ccofb_ctx *ctx, size_t nbytes,
+ const void *in, void *out);
struct _ccmode_ofb_key {
const struct ccmode_ecb *ecb;
ccmode_omac->omac().
key must point to at least sizeof(CCMODE_OMAC_KEY(ecb)) bytes of free
storage. */
-void ccmode_omac_init(const struct ccmode_omac *omac, ccomac_ctx *ctx,
- size_t tweak_len, size_t rawkey_len,
- const void *rawkey);
+int ccmode_omac_init(const struct ccmode_omac *omac, ccomac_ctx *ctx,
+ size_t tweak_len, size_t rawkey_len,
+ const void *rawkey);
struct _ccmode_omac_key {
const struct ccmode_ecb *ecb;
/* Function prototypes used by the macros below, do not call directly. */
-void ccmode_xts_init(const struct ccmode_xts *xts, ccxts_ctx *ctx,
- size_t key_len, const void *data_key,
- const void *tweak_key);
+int ccmode_xts_init(const struct ccmode_xts *xts, ccxts_ctx *ctx,
+ size_t key_nbytes, const void *data_key,
+ const void *tweak_key);
+void ccmode_xts_key_sched(const struct ccmode_xts *xts, ccxts_ctx *ctx,
+ size_t key_nbytes, const void *data_key,
+ const void *tweak_key);
void *ccmode_xts_crypt(const ccxts_ctx *ctx, ccxts_tweak *tweak,
size_t nblocks, const void *in, void *out);
-void ccmode_xts_set_tweak(const ccxts_ctx *ctx, ccxts_tweak *tweak,
- const void *iv);
+int ccmode_xts_set_tweak(const ccxts_ctx *ctx, ccxts_tweak *tweak,
+ const void *iv);
struct _ccmode_xts_key {
.tweak_size = ccn_sizeof_size(sizeof(struct _ccmode_xts_tweak)) + ccn_sizeof_size(ecb->block_size), \
.block_size = ecb->block_size, \
.init = ccmode_xts_init, \
+.key_sched = ccmode_xts_key_sched, \
.set_tweak = ccmode_xts_set_tweak, \
.xts = ccmode_xts_crypt, \
.custom = (ECB), \
.tweak_size = ccn_sizeof_size(sizeof(struct _ccmode_xts_tweak)) + ccn_sizeof_size(ecb->block_size), \
.block_size = ecb->block_size, \
.init = ccmode_xts_init, \
+.key_sched = ccmode_xts_key_sched, \
.set_tweak = ccmode_xts_set_tweak, \
.xts = ccmode_xts_crypt, \
.custom = (ECB), \