Skip to content

Commit

Permalink
* small api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkmnt committed Dec 1, 2021
1 parent 7eece9e commit 14a974b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion aes.c → aes128.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include <stdint.h>
#include "aes.h"
#include "aes128.h"


static inline uint32_t rotr32(uint32_t x, int r)
Expand Down
4 changes: 2 additions & 2 deletions aes.h → aes128.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _AES_H_
#define _AES_H_
#ifndef _AES128_H_
#define _AES128_H_

#define AES128_KMSTORE_NWORDS 8

Expand Down
13 changes: 7 additions & 6 deletions eax128.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void eax128_omac_process(eax128_omac_t *ctx, int byte)
if (ctx->bytepos == 0)
{
xor128(&ctx->mac, &ctx->block);
eax128_cipher(ctx->mac.b, ctx->cipher_ctx);
eax128_cipher(ctx->cipher_ctx, ctx->mac.b);
ctx->block.q[0] = 0;
ctx->block.q[1] = 0;
}
Expand All @@ -115,7 +115,7 @@ void eax128_omac_process(eax128_omac_t *ctx, int byte)
eax128_block_t *eax128_omac_digest(eax128_omac_t *ctx)
{
eax128_block_t tail = {0};
eax128_cipher(tail.b, ctx->cipher_ctx);
eax128_cipher(ctx->cipher_ctx, tail.b);
gf_double(&tail);

if (ctx->bytepos != 0)
Expand All @@ -127,7 +127,7 @@ eax128_block_t *eax128_omac_digest(eax128_omac_t *ctx)
xor128(&ctx->block, &tail);
memset(&tail, 0, sizeof(tail));
xor128(&ctx->mac, &ctx->block);
eax128_cipher(ctx->mac.b, ctx->cipher_ctx);
eax128_cipher(ctx->cipher_ctx, ctx->mac.b);

return &ctx->mac;
}
Expand All @@ -153,7 +153,7 @@ int eax128_ctr_process(eax128_ctr_t *ctx, int pos, int byte)
{
ctx->blocknum = blocknum;
add_ctr(&ctx->xorbuf, &ctx->nonce, blocknum);
eax128_cipher(ctx->xorbuf.b, ctx->cipher_ctx);
eax128_cipher(ctx->cipher_ctx, ctx->xorbuf.b);
}

return ctx->xorbuf.b[pos % 16] ^ byte;
Expand Down Expand Up @@ -203,10 +203,11 @@ int eax128_decrypt_ct(eax128_t *ctx, int pos, int byte)
void eax128_digest(eax128_t *ctx, uint8_t digest[16])
{
eax128_block_t *tag = (eax128_block_t *)(void *)digest;
memset(tag, 0, 16);

eax128_omac_digest(&ctx->ctomac);
xor128(tag, &ctx->ctomac.mac);
eax128_omac_digest(&ctx->headermac);

*tag = ctx->ctomac.mac;
xor128(tag, &ctx->headermac.mac);
xor128(tag, &ctx->ctr.nonce);

Expand Down
2 changes: 1 addition & 1 deletion eax128.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct
// The external cipher function to be linked.
// ctx is the argument passed to cipher. i.e. it may be used to distinguish cipher instances.
// The cipher must process the data in place
extern void eax128_cipher(uint8_t pt[16], void *ctx);
extern void eax128_cipher(void *ctx, uint8_t pt[16]);


void eax128_init(eax128_t *ctx, void *cipher_ctx, const uint8_t *nonce, int nonce_len);
Expand Down
8 changes: 4 additions & 4 deletions eax64.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void eax64_omac_process(eax64_omac_t *ctx, int byte)
{
if (ctx->bytepos == 0)
{
ctx->mac = eax64_cipher(ctx->block.q ^ ctx->mac, ctx->cipher_ctx);
ctx->mac = eax64_cipher(ctx->cipher_ctx, ctx->block.q ^ ctx->mac);
ctx->block.q = 0;

}
Expand All @@ -52,7 +52,7 @@ void eax64_omac_process(eax64_omac_t *ctx, int byte)

uint64_t eax64_omac_digest(eax64_omac_t *ctx)
{
uint64_t tail = eax64_cipher(0, ctx->cipher_ctx);
uint64_t tail = eax64_cipher(ctx->cipher_ctx, 0);
tail = gf_double(tail);

if (ctx->bytepos != 0)
Expand All @@ -61,7 +61,7 @@ uint64_t eax64_omac_digest(eax64_omac_t *ctx)
ctx->block.b[ctx->bytepos] = 0x80;
}

ctx->mac = eax64_cipher(ctx->block.q ^ tail ^ ctx->mac, ctx->cipher_ctx);
ctx->mac = eax64_cipher(ctx->cipher_ctx, ctx->block.q ^ tail ^ ctx->mac);

return ctx->mac;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ int eax64_ctr_process(eax64_ctr_t *ctx, int pos, int byte)
if (BIG_TAIL)
a = byterev64(a);

ctx->xorbuf.q = eax64_cipher(a, ctx->cipher_ctx);
ctx->xorbuf.q = eax64_cipher(ctx->cipher_ctx, a);
}

return ctx->xorbuf.b[pos % 8] ^ byte;
Expand Down
2 changes: 1 addition & 1 deletion eax64.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct

// The external cipher function to be linked.
// ctx is the argument passed to cipher. i.e. it may be used to distinguish cipher instances
extern uint64_t eax64_cipher(uint64_t pt, void *ctx);
extern uint64_t eax64_cipher(void *ctx, uint64_t pt);

void eax64_init(eax64_t *ctx, void *cipher_ctx, const uint8_t *nonce, int nonce_len);
void eax64_auth_ct(eax64_t *ctx, int byte);
Expand Down
4 changes: 2 additions & 2 deletions eax_aes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>

#include "eax128.h"
#include "aes.h"
#include "aes128.h"

#include "vectors_eax_aes.h"

Expand Down Expand Up @@ -55,7 +55,7 @@ void print_dump(const void *data, int len)
printf("\n");
}

extern void eax128_cipher(uint8_t block[16], void *ctx)
extern void eax128_cipher(void *ctx, uint8_t block[16])
{
aes128_encrypt_ecb(&aes_kmstore, block);
}
Expand Down
2 changes: 1 addition & 1 deletion eax_xtea_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void print_dump(const void *data, int len)
printf("\n");
}

uint64_t eax64_cipher(uint64_t pt, void *ctx)
uint64_t eax64_cipher(void *ctx, uint64_t pt)
{
return xtea_ecb(pt);
}
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ all: eax_xtea_test.exe eax_aes_test.exe
eax_xtea_test.exe: eax64.c eax_xtea_test.c
gcc $(FLAGS) --output $@ $^

eax_aes_test.exe: eax128.c eax_aes_test.c aes.c
eax_aes_test.exe: eax128.c eax_aes_test.c aes128.c
gcc $(FLAGS) --output $@ $^

clean:
Expand Down

0 comments on commit 14a974b

Please sign in to comment.