]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
[keccak-asm] *_lastBlock in asm
authorbg <daniel.otte@rub.de>
Sun, 13 Jan 2013 22:55:21 +0000 (23:55 +0100)
committerbg <daniel.otte@rub.de>
Sun, 13 Jan 2013 22:55:21 +0000 (23:55 +0100)
keccak/keccak-asm.S
keccak/keccak-stub.c
keccak/keccak.c

index 393535b1407c1dcb83db25942ccf6778fcab99d4..db8548cb4f44383a9caced05b95c32198d43860f 100644 (file)
@@ -789,3 +789,125 @@ keccak_init_1:
        ret
        .endfunc
 
+/*
+void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){
+    uint8_t length_B;
+    uint8_t t;
+    while(length_b >= ctx->r){
+        keccak_nextBlock(ctx, block);
+        block = (uint8_t*)block + ctx->bs;
+        length_b -=  ctx->r;
+    }
+    length_B = length_b / 8;
+    memxor(ctx->a, block, length_B);
+    / * append 1 * /
+    if(length_b & 7){
+        / * we have some single bits * /
+        t = ((uint8_t*)block)[length_B] >> (8 - (length_b & 7));
+        t |= 0x01 << (length_b & 7);
+    }else{
+        t = 0x01;
+    }
+    ctx->a[length_B] ^= t;
+    if(length_b == ctx->r - 1){
+        keccak_f1600(ctx->a);
+    }
+
+*/
+.set length_b_l,  2
+.set length_b_h,  3
+.set pbs,     10
+.set pr_l,     8
+.set pr_h,      9
+.set ctx_l,       6
+.set ctx_h,       7
+
+       .global keccak_lastBlock
+       .func keccak_lastBlock
+keccak_lastBlock:
+       push_range 2, 10
+       movw r2, r20
+       movw r4, r22
+       movw r6, r24
+       movw XL, r24
+       subi XL, lo8(-ctx_r)
+       sbci XH, hi8(-ctx_r)
+       ld  pr_l, X+
+       ld  pr_h, X+
+       ld  pbs, X
+10:
+       cp  length_b_l, pr_l
+       cpc length_b_h, pr_h
+       brlo 20f
+       movw r24, ctx_l
+       movw r22, r4
+       rcall keccak_nextBlock
+       sub r4, pbs
+       sbc r5, __zero_reg__
+       sub length_b_l, pr_l
+       sbc length_b_l, pr_h
+       rjmp 10b
+20:
+       movw XL, r4
+       movw ZL, ctx_l
+       movw r22, length_b_l
+       lsr r23
+       ror r22
+       lsr r23
+       ror r22
+       lsr r23
+       ror r22
+       mov r23, r22
+       breq 20f
+10:
+       ld r25, X+
+       ld r24, Z
+       eor r24, r25
+       st Z+, r24
+       dec r23
+       brne 10b
+20:
+       mov r18, length_b_l
+       andi r18, 7
+       mov r19, r18
+       ldi r25, 1
+       breq 30f
+       /* we have trailing bits */
+       ld r24, X+
+       subi r18, 8
+       neg r18
+10:
+       lsr r24
+       dec r18
+       brne 10b
+10:
+       lsl r25
+       dec r19
+       brne 10b
+       or r25, r24
+30:
+       ld r24, Z
+       eor r24, r25
+       st Z, r24
+
+       movw r24, pr_l
+       sbiw r24, 1
+       cp  length_b_l, r24
+       cpc length_b_h, r25
+       brne 20f
+       movw r24, ctx_l
+       rcall keccak_f1600
+20:
+       movw XL, ctx_l
+       dec pbs
+       add XL, pbs
+       adc XH, __zero_reg__
+       ld r24, X
+       ldi r25, 0x80
+       eor r24, r25
+       st X, r24
+       movw r24, ctx_l
+       pop_range 2, 10
+       rjmp keccak_f1600
+       .endfunc
+
index d7dabf24fea74da74239338f9ad7749f431f8337..14c91df774efb3072aa4a72d1c69ca0e256d81b6 100644 (file)
 #include "memxor.h"
 #include "keccak.h"
 
-void keccak_f1600(uint8_t a[200]);
-
+/*
+//void keccak_f1600(uint8_t a[200]);
+void keccak_lastBlock_f1(keccak_ctx_t* ctx, const void* block, uint16_t length_b);
 void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){
-    uint8_t length_B;
-    while(length_b >= ctx->r){
-        keccak_nextBlock(ctx, block);
-        block = (uint8_t*)block + ctx->bs;
-        length_b -=  ctx->r;
-    }
-    length_B = length_b / 8;
-    memxor(ctx->a, block, length_B);
-    /* append 1 */
-    if(length_b & 7){
-        /* we have some single bits */
-        uint8_t t;
-        t = ((uint8_t*)block)[length_B] >> (8 - (length_b & 7));
-        t |= 0x01 << (length_b & 7);
-        ctx->a[length_B] ^= t;
-    }else{
-        ctx->a[length_B] ^= 0x01;
-    }
-    if(length_b == ctx->r - 1){
-        keccak_f1600(ctx->a);
-    }
-    ctx->a[ctx->bs - 1] ^= 0x80;
-    keccak_f1600(ctx->a);
+    keccak_lastBlock_f1(ctx, block, length_b);
+ //   ctx->a[ctx->bs - 1] ^= 0x80;
+ //   keccak_f1600(ctx->a);
 }
 
-
+*/
index 6327595ea761467fb74c9d77e77ae2b0c3cab96b..506c77c2b6da5dd377de432e5f1a3412f554881e 100644 (file)
@@ -179,6 +179,7 @@ void keccak_nextBlock(keccak_ctx_t* ctx, const void* block){
 
 void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){
     uint8_t length_B;
+    uint8_t t;
     while(length_b >= ctx->r){
         keccak_nextBlock(ctx, block);
         block = (uint8_t*)block + ctx->bs;
@@ -189,13 +190,12 @@ void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){
     /* append 1 */
     if(length_b & 7){
         /* we have some single bits */
-        uint8_t t;
         t = ((uint8_t*)block)[length_B] >> (8 - (length_b & 7));
-        t |= 0x01 << (length_b & 7);
-        ctx->a[length_B] ^= t;
+        t |= 0x01 << (length_b & 7);;
     }else{
-        ctx->a[length_B] ^= 0x01;
+        = 0x01;
     }
+    ctx->a[length_B] ^= t
     if(length_b == ctx->r - 1){
         keccak_f1600(ctx->a);
     }