X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=camellia.c;h=4c5b1c85e020b254079952dabf94e2b11120d148;hb=12883cff6e7d233365e8477e08f90c75fa5a48b2;hp=a561d4ee2f637e851207dc687d21477581fcb370;hpb=d5e258765801a9b13be0e0502de94d7cb8c40629;p=avr-crypto-lib.git diff --git a/camellia.c b/camellia.c index a561d4e..4c5b1c8 100644 --- a/camellia.c +++ b/camellia.c @@ -63,8 +63,8 @@ uint32_t PROGMEM camellia_sigma[12]={ /* 48 byte table */ #define SIGMA(p) (( ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+1)))<<32) | \ ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+0))) ) */ -#define SIGMA(p) (( ((uint64_t)(pgm_read_dword(((prog_uint32_t*)camellia_sigma)[2*(p)+1])))<<32) | \ - ((uint64_t)(pgm_read_dword(((prog_uint32_t*)camellia_sigma)[2*(p)+0]))) ) +#define SIGMA(p) (( ((uint64_t)(pgm_read_dword(&(((prog_uint32_t*)camellia_sigma)[2*(p)+1]))))<<32) | \ + ((uint64_t)(pgm_read_dword(&(((prog_uint32_t*)camellia_sigma)[2*(p)+0])))) ) @@ -82,7 +82,7 @@ void camellia128_ctx_dump(camellia128_ctx_t *s){ /*****************************************************************************/ /* extern prog_uint64_t camellia_sigma[6]; */ -void camellia128_init(uint8_t* key, camellia128_ctx_t* s){ +void camellia128_init(const uint8_t* key, camellia128_ctx_t* s){ uint8_t i; s->kll = 0; /* ((uint64_t*)key)[0]; */ @@ -112,7 +112,7 @@ void camellia128_init(uint8_t* key, camellia128_ctx_t* s){ /*****************************************************************************/ void camellia128_keyop(camellia128_ctx_t* s, int8_t q); /*****************************************************************************/ -void camellia128_keyop_inv(camellia128_ctx_t* s, int8_t q); +void camellia128_keyop_inv(camellia128_ctx_t* s, int8_t q); /*****************************************************************************/ #define SEL_KA 1 @@ -130,12 +130,12 @@ void camellia128_keyop_inv(camellia128_ctx_t* s, int8_t q); #define KEY_ROL17 0x08 #define KEY_ROL15 0x00 -void camellia_6rounds(camellia128_ctx_t* s, uint64_t* bl, uint64_t* br, +void camellia_6rounds(const camellia128_ctx_t* s, uint64_t* bl, uint64_t* br, uint8_t roundop, uint8_t keychoice); /*****************************************************************************/ -void camellia128_enc(void* block, camellia128_ctx_t* s){ +void camellia128_enc(void* block, const camellia128_ctx_t* s){ #define BL (((uint64_t*)block)[0]) #define BR (((uint64_t*)block)[1]) @@ -157,17 +157,17 @@ void camellia128_enc(void* block, camellia128_ctx_t* s){ /* the first 6 */ camellia_6rounds(s, &BL, &BR, KEY_ROL15 | KEY_DIR_NORM | KEY_POSTC1 , 0x33); /* FL injection */ - camellia128_keyop(s, -1); + camellia128_keyop((camellia128_ctx_t*)s, -1); BL = camellia_fl(BL, s->kal); BR = camellia_fl_inv(BR, s->kar); - camellia128_keyop(s, -1); + camellia128_keyop((camellia128_ctx_t*)s, -1); /* middle 6 */ camellia_6rounds(s, &BL, &BR, KEY_ROL15 | KEY_DIR_NORM | KEY_INC2 , 0x34); /* FL injection */ - camellia128_keyop(s, 1); + camellia128_keyop((camellia128_ctx_t*)s, 1); BL = camellia_fl(BL, s->kll); BR = camellia_fl_inv(BR, s->klr); - camellia128_keyop(s, 1); + camellia128_keyop((camellia128_ctx_t*)s, 1); /* last 6 */ camellia_6rounds(s, &BL, &BR, KEY_ROL17 | KEY_DIR_NORM | KEY_POSTC2 , 0x0C); /* Postwhitening */ @@ -178,7 +178,7 @@ void camellia128_enc(void* block, camellia128_ctx_t* s){ BR = BL; BL = temp64; - camellia128_keyop(s,1); + camellia128_keyop((camellia128_ctx_t*)s,1); change_endian(&BL, 64/8); change_endian(&BR, 64/8); @@ -189,14 +189,14 @@ void camellia128_enc(void* block, camellia128_ctx_t* s){ /*****************************************************************************/ -void camellia128_dec(void* block, camellia128_ctx_t* s){ +void camellia128_dec(void* block, const camellia128_ctx_t* s){ #define BL (((uint64_t*)block)[1]) #define BR (((uint64_t*)block)[0]) /* endian adjustment */ /*BL*/ - /* 1 2 3 4 5 6 7 8 - * 8 7 6 5 4 3 2 1 + /* 1 2 3 4 5 6 7 8 + * 8 7 6 5 4 3 2 1 */ uint64_t temp64; @@ -204,24 +204,24 @@ void camellia128_dec(void* block, camellia128_ctx_t* s){ change_endian(&BL, 64/8); change_endian(&BR, 64/8); - camellia128_keyop_inv(s, 1); + camellia128_keyop_inv((camellia128_ctx_t*)s, 1); /* Prewhitening */ BR ^= s->kal; /* kw3 */ BL ^= s->kar; /* kw4 */ /* the first 6 */ camellia_6rounds(s, &BR, &BL, KEY_ROL17 | KEY_DIR_INV | KEY_POSTC1 , 0x0C); /* FL injection */ - camellia128_keyop_inv(s, 1); + camellia128_keyop_inv((camellia128_ctx_t*)s, 1); BR = camellia_fl(BR, s->klr); BL = camellia_fl_inv(BL, s->kll); - camellia128_keyop_inv(s, 1); + camellia128_keyop_inv((camellia128_ctx_t*)s, 1); /* middle 6 */ camellia_6rounds(s, &BR, &BL, KEY_ROL15 | KEY_DIR_INV | KEY_INC2 , 0x0B); /* FL injection */ - camellia128_keyop_inv(s, -1); + camellia128_keyop_inv((camellia128_ctx_t*)s, -1); BR = camellia_fl(BR, s->kar); BL = camellia_fl_inv(BL, s->kal); - camellia128_keyop_inv(s, -1); + camellia128_keyop_inv((camellia128_ctx_t*)s, -1); /* last 6 */ camellia_6rounds(s, &BR, &BL, KEY_ROL15 | KEY_DIR_INV | KEY_POSTC2 , 0x33);