* 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){
}
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){
}
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){
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
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+
st Z+, A5
st Z+, A6
st Z+, A7
+9:
pop_range 14, 17
ret
sbc r0, r1
st X+, r0
ld r0, X
- adc r0, r1
+ sbc r0, r1
st X+, r0
tst S
brne 3f
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
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+
ld r0, X+
eor A7, r0
st Z+, r0
+
st Z+, A0
st Z+, A1
st Z+, A2
st Z+, A5
st Z+, A6
st Z+, A7
+9:
pop_range 14, 17
ret
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+
st Z+, A5
st Z+, A6
st Z+, A7
+9:
pop_range 14, 17
ret
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
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+
st Z+, A5
st Z+, A6
st Z+, A7
+9:
pop_range 14, 17
ret