fixing a bug in threefish-256 decryption assembler module
This commit is contained in:
parent
d1d3ca6487
commit
ff9f1b74e7
|
@ -41,10 +41,22 @@ char* algo_name = "Threefish";
|
|||
* additional validation-functions *
|
||||
*****************************************************************************/
|
||||
|
||||
void threefish256_dump(threefish256_ctx_t* ctx){
|
||||
uint8_t i;
|
||||
cli_putstr_P(PSTR("\r\n=== ctx dump (256) === \r\n k: "));
|
||||
for(i=0; i<5; ++i){
|
||||
cli_hexdump(&(ctx->k[i]), 8);
|
||||
cli_putc(' ');
|
||||
}
|
||||
cli_putstr_P(PSTR("\r\n t: "));
|
||||
for(i=0; i<3; ++i){
|
||||
cli_hexdump(&(ctx->t[i]), 8);
|
||||
cli_putc(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void threefish256_dummy_init(const uint8_t* key, uint16_t keysize_b, void* ctx){
|
||||
uint8_t null[16];
|
||||
memset(null, 0, 16);
|
||||
threefish256_init(key, null, ctx);
|
||||
threefish256_init(key, NULL, ctx);
|
||||
}
|
||||
|
||||
void testrun_nessie_threefish256(void){
|
||||
|
@ -61,9 +73,7 @@ void testrun_nessie_threefish256(void){
|
|||
}
|
||||
|
||||
void threefish512_dummy_init(const uint8_t* key, uint16_t keysize_b, void* ctx){
|
||||
uint8_t null[16];
|
||||
memset(null, 0, 16);
|
||||
threefish512_init(key, null, ctx);
|
||||
threefish512_init(key, NULL, ctx);
|
||||
}
|
||||
|
||||
void testrun_nessie_threefish512(void){
|
||||
|
@ -80,9 +90,7 @@ void testrun_nessie_threefish512(void){
|
|||
}
|
||||
|
||||
void threefish1024_dummy_init(const uint8_t* key, uint16_t keysize_b, void* ctx){
|
||||
uint8_t null[16];
|
||||
memset(null, 0, 16);
|
||||
threefish1024_init(key, null, ctx);
|
||||
threefish1024_init(key, NULL, ctx);
|
||||
}
|
||||
|
||||
void testrun_nessie_threefish1024(void){
|
||||
|
|
|
@ -62,13 +62,17 @@ void permute_16(void* data){
|
|||
|
||||
void threefish1024_init(const void* key, const void* tweak, threefish1024_ctx_t* ctx){
|
||||
memcpy(ctx->k, key, 16*8);
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
if(tweak){
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}else{
|
||||
memset(ctx, 0, 3*8);
|
||||
}
|
||||
uint8_t i;
|
||||
ctx->k[16] = THREEFISH_KEY_CONST;
|
||||
for(i=0; i<16; ++i){
|
||||
ctx->k[16] ^= K(i);
|
||||
}
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
@ -103,6 +103,17 @@ threefish1024_init:
|
|||
st Z+, A7
|
||||
/* now the tweak */
|
||||
movw r26, r22
|
||||
tst r27
|
||||
brne 3f
|
||||
tst r26
|
||||
brne 3f
|
||||
ldi r26, 3*8
|
||||
1:
|
||||
st Z+, r1
|
||||
dec r26
|
||||
brne 1b
|
||||
rjmp 9f
|
||||
3:
|
||||
ld A0, X+
|
||||
ld A1, X+
|
||||
ld A2, X+
|
||||
|
@ -151,6 +162,7 @@ threefish1024_init:
|
|||
st Z+, A5
|
||||
st Z+, A6
|
||||
st Z+, A7
|
||||
9:
|
||||
pop_range 14, 17
|
||||
ret
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ threefish256_dec:
|
|||
sbc r0, r1
|
||||
st X+, r0
|
||||
ld r0, X
|
||||
adc r0, r1
|
||||
sbc r0, r1
|
||||
st X+, r0
|
||||
tst S
|
||||
brne 3f
|
||||
|
|
|
@ -46,13 +46,17 @@ void permute_4(void* data){
|
|||
|
||||
void threefish256_init(const void* key, const void* tweak, threefish256_ctx_t* ctx){
|
||||
memcpy(ctx->k, key, 4*8);
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
if(tweak){
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}else{
|
||||
memset(ctx->t, 0, 3*8);
|
||||
}
|
||||
uint8_t i;
|
||||
ctx->k[4] = THREEFISH_KEY_CONST;
|
||||
for(i=0; i<4; ++i){
|
||||
ctx->k[4] ^= K(i);
|
||||
}
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
@ -103,6 +103,17 @@ threefish256_init:
|
|||
st Z+, A6
|
||||
st Z+, A7
|
||||
/* now the tweak */
|
||||
tst r23
|
||||
brne 3f
|
||||
tst r22
|
||||
brne 3f
|
||||
ldi r26, 3*8
|
||||
2:
|
||||
st Z+, r1
|
||||
dec r26
|
||||
brne 2b
|
||||
rjmp 9f
|
||||
3:
|
||||
movw r26, r22
|
||||
ld A0, X+
|
||||
ld A1, X+
|
||||
|
@ -144,6 +155,7 @@ threefish256_init:
|
|||
ld r0, X+
|
||||
eor A7, r0
|
||||
st Z+, r0
|
||||
|
||||
st Z+, A0
|
||||
st Z+, A1
|
||||
st Z+, A2
|
||||
|
@ -152,6 +164,7 @@ threefish256_init:
|
|||
st Z+, A5
|
||||
st Z+, A6
|
||||
st Z+, A7
|
||||
9:
|
||||
pop_range 14, 17
|
||||
ret
|
||||
|
||||
|
|
|
@ -104,6 +104,17 @@ threefish256_init:
|
|||
st Z+, A7
|
||||
/* now the tweak */
|
||||
movw r26, r22
|
||||
tst r27
|
||||
brne 3f
|
||||
tst r26
|
||||
brne 3f
|
||||
ldi r26, 3*8
|
||||
1:
|
||||
st Z+, r1
|
||||
dec r26
|
||||
brne 1b
|
||||
rjmp 9f
|
||||
3:
|
||||
ld A0, X+
|
||||
ld A1, X+
|
||||
ld A2, X+
|
||||
|
@ -152,6 +163,7 @@ threefish256_init:
|
|||
st Z+, A5
|
||||
st Z+, A6
|
||||
st Z+, A7
|
||||
9:
|
||||
pop_range 14, 17
|
||||
ret
|
||||
|
||||
|
|
|
@ -68,13 +68,17 @@ void permute_inv8(void* data){
|
|||
|
||||
void threefish512_init(const void* key, const void* tweak, threefish512_ctx_t* ctx){
|
||||
memcpy(ctx->k, key, 8*8);
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
if(tweak){
|
||||
memcpy(ctx->t, tweak, 2*8);
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}else{
|
||||
memset(ctx->t, 0, 3*8);
|
||||
}
|
||||
uint8_t i;
|
||||
ctx->k[8] = THREEFISH_KEY_CONST;
|
||||
for(i=0; i<8; ++i){
|
||||
ctx->k[8] ^= K(i);
|
||||
}
|
||||
ctx->t[2] = T(0) ^ T(1);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
@ -103,6 +103,17 @@ threefish512_init:
|
|||
st Z+, A7
|
||||
/* now the tweak */
|
||||
movw r26, r22
|
||||
tst r27
|
||||
brne 3f
|
||||
tst r26
|
||||
brne 3f
|
||||
ldi r26, 3*8
|
||||
1:
|
||||
st Z+, r1
|
||||
dec r26
|
||||
brne 1b
|
||||
rjmp 9f
|
||||
3:
|
||||
ld A0, X+
|
||||
ld A1, X+
|
||||
ld A2, X+
|
||||
|
@ -151,6 +162,7 @@ threefish512_init:
|
|||
st Z+, A5
|
||||
st Z+, A6
|
||||
st Z+, A7
|
||||
9:
|
||||
pop_range 14, 17
|
||||
ret
|
||||
|
||||
|
|
Loading…
Reference in New Issue