Commit 7db20b14 authored by Niels Möller's avatar Niels Möller
Browse files

Reindent CMAC code to GNU standard, white space changes only.

parent a254a776
......@@ -52,7 +52,8 @@ static const uint8_t const_zero[] = {
};
/* shift one and XOR with 0x87. */
static inline void block_mulx(union nettle_block16 *dst,
static inline void
block_mulx(union nettle_block16 *dst,
const union nettle_block16 *src)
{
uint64_t b1 = READ_UINT64(src->b);
......@@ -68,7 +69,8 @@ static inline void block_mulx(union nettle_block16 *dst,
WRITE_UINT64(dst->b+8, b2);
}
void cmac128_set_key(struct cmac128 *ctx, void *cipher,
void
cmac128_set_key(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt)
{
union nettle_block16 *L = &ctx->block;
......@@ -83,7 +85,8 @@ void cmac128_set_key(struct cmac128 *ctx, void *cipher,
#define MIN(x,y) ((x)<(y)?(x):(y))
void cmac128_update(struct cmac128 *ctx, void *cipher,
void
cmac128_update(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt,
size_t msg_len, const uint8_t *msg)
{
......@@ -91,7 +94,8 @@ void cmac128_update(struct cmac128 *ctx, void *cipher,
/*
* check if we expand the block
*/
if (ctx->index < 16) {
if (ctx->index < 16)
{
size_t len = MIN(16 - ctx->index, msg_len);
memcpy(&ctx->block.b[ctx->index], msg, len);
msg += len;
......@@ -110,7 +114,8 @@ void cmac128_update(struct cmac128 *ctx, void *cipher,
memxor3(Y.b, ctx->X.b, ctx->block.b, 16);
encrypt(cipher, 16, ctx->X.b, Y.b);
while (msg_len > 16) {
while (msg_len > 16)
{
memxor3(Y.b, ctx->X.b, msg, 16);
encrypt(cipher, 16, ctx->X.b, Y.b);
msg += 16;
......@@ -125,7 +130,8 @@ void cmac128_update(struct cmac128 *ctx, void *cipher,
ctx->index = msg_len;
}
void cmac128_digest(struct cmac128 *ctx, void *cipher,
void
cmac128_digest(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt,
unsigned length,
uint8_t *dst)
......@@ -135,19 +141,25 @@ void cmac128_digest(struct cmac128 *ctx, void *cipher,
memset(ctx->block.b+ctx->index, 0, sizeof(ctx->block.b)-ctx->index);
/* re-use ctx->block for memxor output */
if (ctx->index < 16) {
if (ctx->index < 16)
{
ctx->block.b[ctx->index] = 0x80;
memxor(ctx->block.b, ctx->K2.b, 16);
} else {
}
else
{
memxor(ctx->block.b, ctx->K1.b, 16);
}
memxor3(Y.b, ctx->block.b, ctx->X.b, 16);
assert(length <= 16);
if (length == 16) {
if (length == 16)
{
encrypt(cipher, 16, dst, Y.b);
} else {
}
else
{
encrypt(cipher, 16, ctx->block.b, Y.b);
memcpy(dst, ctx->block.b, length);
}
......
......@@ -55,7 +55,8 @@ extern "C" {
#define cmac_aes256_update nettle_cmac_aes256_update
#define cmac_aes256_digest nettle_cmac_aes256_digest
struct cmac128 {
struct cmac128
{
union nettle_block16 K1;
union nettle_block16 K2;
......@@ -65,12 +66,15 @@ struct cmac128 {
size_t index;
};
void cmac128_set_key(struct cmac128 *ctx, void *cipher,
void
cmac128_set_key(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt);
void cmac128_update(struct cmac128 *ctx, void *cipher,
void
cmac128_update(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt,
size_t msg_len, const uint8_t *msg);
void cmac128_digest(struct cmac128 *ctx, void *cipher,
void
cmac128_digest(struct cmac128 *ctx, void *cipher,
nettle_cipher_func *encrypt,
unsigned length,
uint8_t *out);
......
......@@ -143,4 +143,3 @@ test_main(void)
SHEX("e1992190549f6ed5696a2c056c315410"));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment