Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F167926334
D33488.id100106.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D33488.id100106.diff
View Options
Index: sys/opencrypto/xform_cml.c
===================================================================
--- sys/opencrypto/xform_cml.c
+++ sys/opencrypto/xform_cml.c
@@ -53,9 +53,15 @@
#include <crypto/camellia/camellia.h>
#include <opencrypto/xform_enc.h>
+struct camellia_cbc_ctx {
+ camellia_ctx state;
+ char iv[CAMELLIA_BLOCK_LEN];
+};
+
static int cml_setkey(void *, const uint8_t *, int);
static void cml_encrypt(void *, const uint8_t *, uint8_t *);
static void cml_decrypt(void *, const uint8_t *, uint8_t *);
+static void cml_reinit(void *, const uint8_t *, size_t);
/* Encryption instances */
const struct enc_xform enc_xform_camellia = {
@@ -69,30 +75,55 @@
.encrypt = cml_encrypt,
.decrypt = cml_decrypt,
.setkey = cml_setkey,
+ .reinit = cml_reinit,
};
/*
* Encryption wrapper routines.
*/
static void
-cml_encrypt(void *ctx, const uint8_t *in, uint8_t *out)
+cml_encrypt(void *vctx, const uint8_t *in, uint8_t *out)
{
- camellia_encrypt(ctx, in, out);
+ struct camellia_cbc_ctx *ctx = vctx;
+
+ for (u_int i = 0; i < CAMELLIA_BLOCK_LEN; i++)
+ out[i] = in[i] ^ ctx->iv[i];
+ camellia_encrypt(&ctx->state, in, out);
+ memcpy(ctx->iv, out, CAMELLIA_BLOCK_LEN);
}
static void
-cml_decrypt(void *ctx, const uint8_t *in, uint8_t *out)
+cml_decrypt(void *vctx, const uint8_t *in, uint8_t *out)
{
- camellia_decrypt(ctx, in, out);
+ struct camellia_cbc_ctx *ctx = vctx;
+ char block[CAMELLIA_BLOCK_LEN];
+
+ memcpy(block, in, CAMELLIA_BLOCK_LEN);
+ camellia_decrypt(&ctx->state, in, out);
+ for (u_int i = 0; i < CAMELLIA_BLOCK_LEN; i++)
+ out[i] ^= ctx->iv[i];
+ memcpy(ctx->iv, block, CAMELLIA_BLOCK_LEN);
+ explicit_bzero(block, sizeof(block));
}
static int
-cml_setkey(void *ctx, const uint8_t *key, int len)
+cml_setkey(void *vctx, const uint8_t *key, int len)
{
+ struct camellia_cbc_ctx *ctx = vctx;
if (len != 16 && len != 24 && len != 32)
return (EINVAL);
- camellia_set_key(ctx, key, len * 8);
+ camellia_set_key(&ctx->state, key, len * 8);
return (0);
}
+
+static void
+cml_reinit(void *vctx, const uint8_t *iv, size_t iv_len)
+{
+ struct camellia_cbc_ctx *ctx = vctx;
+
+ KASSERT(iv_len == sizeof(ctx->iv), ("%s: bad IV length", __func__));
+ memcpy(ctx->iv, iv, sizeof(ctx->iv));
+}
+
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 26, 11:26 AM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37291532
Default Alt Text
D33488.id100106.diff (2 KB)
Attached To
Mode
D33488: crypto: Move CBC handling into enc_xform_camellia.
Attached
Detach File
Event Timeline
Log In to Comment