]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - bmw/bmw_small-asm.S
turning on software flow control for uart
[avr-crypto-lib.git] / bmw / bmw_small-asm.S
index 03f87028d49e6eaee8ed80a4286e7a7a7eff6595..03f1ba57a698d93fbeb5c85387b4ef3399bbb9e2 100644 (file)
@@ -1,7 +1,7 @@
 /* bmw_small-asm.S */
 /*
     This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
+    Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -510,7 +510,7 @@ const_lut:
        .long 0x9555554c, 0x9aaaaaa1, 0x9ffffff6, 0xa555554b
 
 /*******************************************************************************
-* uint32_t addelment(uint8_t j, const uint32_t* m, const uint32_t* h){
+* uint32_t addelment(uint8_t j, const uint32_t *m, const uint32_t *h){
 *      uint32_t r;
 *      r  = pgm_read_dword(k_lut+j);
 *      r += rotl_addel(((uint32_t*)m)[j&0xf], j+0);
@@ -538,12 +538,11 @@ addelement:
        mov j, r24
        movw h0, r20
        movw m0, r22
-       mov r25, r24
-       lsl r25
-       lsl r25
+       lsl r24
+       lsl r24
        ldi r30, lo8(const_lut)
        ldi r31, hi8(const_lut)
-       add r30, r25
+       add r30, r24
        adc r31, r1
        lpm acc0, Z+
        lpm acc1, Z+
@@ -626,7 +625,7 @@ addelement:
        ret
 
 /*******************************************************************************
-* uint32_t bmw_small_expand1(uint8_t j, const void* m, const void* h, const uint32_t* q){
+* uint32_t bmw_small_expand1(uint8_t j, const void *m, const void *h, const uint32_t *q){
 *      uint32_t(*s[])(uint32_t) = {bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s0};
 *      uint32_t r;
 *      uint8_t i;
@@ -709,7 +708,7 @@ expand1_exit:
        ret
 
 /*******************************************************************************
-* uint32_t bmw_small_expand2(uint8_t j, const void* m, const void* h, const uint32_t* q){
+* uint32_t bmw_small_expand2(uint8_t j, const void *m, const void *h, const uint32_t *q){
 *      uint32_t(*rf[])(uint32_t) = {bmw_small_r1, bmw_small_r2, bmw_small_r3,
 *                                   bmw_small_r4, bmw_small_r5, bmw_small_r6,
 *                                                           bmw_small_r7};
@@ -782,7 +781,7 @@ bmw_small_expand2:
        rjmp expand1_exit
 
 /*******************************************************************************
-* void bmw_small_f1(uint32_t* q, const void* m, const void* h){
+* void bmw_small_f1(uint32_t *q, const void *m, const void *h){
 *      uint8_t i;
 *      q[16] = bmw_small_expand1(0, m, h, q);
 *      q[17] = bmw_small_expand1(1, m, h, q);
@@ -850,7 +849,7 @@ bmw_small_f1:
 * uint16_t hack_table[5]   PROGMEM = { 0x0311, 0xDDB3, 0x2A79, 0x07AA, 0x51C2 };
 * uint8_t  offset_table[5] PROGMEM = { 4+16, 6+16, 9+16, 12+16, 13+16 };
 *
-* void bmw_small_f0(uint32_t* h, const void* m, uint32_t* q){
+* void bmw_small_f0(uint32_t *h, const void *m, uint32_t *q){
 *      uint16_t hack_reg;
 *      uint8_t c,i,j;
 *      uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2,
@@ -1110,7 +1109,7 @@ bmw_small_f0:
     ret
 
 /*******************************************************************************
-* void bmw_small_f2(uint32_t* h, const uint32_t* q, const void* m){
+* void bmw_small_f2(uint32_t *h, const uint32_t *q, const void *m){
 *      uint32_t xl=0, xh;
 *      uint8_t i;
 *      for(i=16;i<24;++i){
@@ -1700,7 +1699,7 @@ cli_putchar:
 #endif
 
 /*******************************************************************************
-* void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){
+* void bmw_small_nextBlock(bmw_small_ctx_t *ctx, const void *block){
 *      uint32_t q[32];
 *      dump_x(block, 16, 'M');
 *      bmw_small_f0(ctx->h, block, q);
@@ -1770,7 +1769,7 @@ bmw256_nextBlock:
 
 
 /*******************************************************************************
-* void bmw224_init(bmw224_ctx_tctx){
+* void bmw224_init(bmw224_ctx_t *ctx){
 *      uint8_t i;
 *      ctx->h[0] = 0x00010203;
 *      for(i=1; i<16; ++i){
@@ -1822,7 +1821,7 @@ bmw256_init:
        rjmp bmw_small_init
 
 /*******************************************************************************
-* void bmw_small_lastBlock(bmw_small_ctx_t* ctx, const void* block, uint16_t length_b){
+* void bmw_small_lastBlock(bmw_small_ctx_t *ctx, const void *block, uint16_t length_b){
 *      struct {
 *              uint8_t  buffer[64];
 *              uint32_t ctr;
@@ -2042,7 +2041,7 @@ bmw256_lastBlock:
        ret
 
 /*******************************************************************************
-* void bmw224_ctx2hash(void* dest, const bmw224_ctx_t* ctx){
+* void bmw224_ctx2hash(void *dest, const bmw224_ctx_t *ctx){
 *      memcpy(dest, &(ctx->h[9]), 224/8);
 * }
 *
@@ -2058,7 +2057,7 @@ bmw224_ctx2hash:
        rjmp 1f
 
 /*******************************************************************************
-* void bmw256_ctx2hash(void* dest, const bmw256_ctx_t* ctx){
+* void bmw256_ctx2hash(void *dest, const bmw256_ctx_t *ctx){
 *      memcpy(dest, &(ctx->h[8]), 256/8);
 * }
 *
@@ -2079,7 +2078,7 @@ bmw256_ctx2hash:
        ret
 
 /*******************************************************************************
-* void bmw256(void* dest, const void* msg, uint32_t length_b){
+* void bmw256(void *dest, const void *msg, uint32_t length_b){
 *      bmw_small_ctx_t ctx;
 *      bmw256_init(&ctx);
 *      while(length_b>=BMW_SMALL_BLOCKSIZE){
@@ -2107,46 +2106,12 @@ dst0 =  10
 dst1 =  11
 .global bmw256
 bmw256:
-       push_range 2, 11
-       stack_alloc_large 64+4
-       adiw r30, 1
-       movw ctx0, r30
-       movw dst0, r24
-       movw msg0, r22
-       movw len0, r18
-       movw len2, r20
-       movw r24, ctx0
-       rcall bmw256_init
-20:
-       mov r18, len2
-       or  r18, len3
-       breq 50f
-       movw r24, ctx0
-       movw r22, msg0
-       rcall bmw_small_nextBlock
-       ldi r20, 2
-       sub len1, r20
-       sbc len2, r1
-       sbc len3, r1
-       ldi r20, 64
-       add msg0, r20
-       adc msg1, r1
-       rjmp 20b
-50:
-       movw r24, ctx0
-       movw r22, msg0
-       movw r20, len0
-       rcall bmw_small_lastBlock
-       movw r24, dst0
-       movw r22, ctx0
-       rcall bmw256_ctx2hash
-       stack_free_large 64+4
-       pop_range 2, 11
-       ret
-
+       push r16
+       ldi r16, 1
+       rjmp bmw_small_all
 
 /*******************************************************************************
-* void bmw224(void* dest, const void* msg, uint32_t length_b){
+* void bmw224(void *dest, const void *msg, uint32_t length_b){
 *      bmw_small_ctx_t ctx;
 *      bmw224_init(&ctx);
 *      while(length_b>=BMW_SMALL_BLOCKSIZE){
@@ -2174,6 +2139,10 @@ dst0 =  10
 dst1 =  11
 .global bmw224
 bmw224:
+       push r16
+       clr r16
+
+bmw_small_all:
        push_range 2, 11
        stack_alloc_large 64+4
        adiw r30, 1
@@ -2183,7 +2152,11 @@ bmw224:
        movw len0, r18
        movw len2, r20
        movw r24, ctx0
-       rcall bmw224_init
+       ldi r30, pm_lo8(init_lut)
+       ldi r31, pm_hi8(init_lut)
+       add r30, r16
+       adc r31, r1
+       icall
 20:
        mov r18, len2
        or  r18, len3
@@ -2206,7 +2179,19 @@ bmw224:
        rcall bmw_small_lastBlock
        movw r24, dst0
        movw r22, ctx0
-       rcall bmw224_ctx2hash
+       ldi r30, pm_lo8(c2h_lut)
+       ldi r31, pm_hi8(c2h_lut)
+       add r30, r16
+       adc r31, r1
+       icall
        stack_free_large 64+4
        pop_range 2, 11
+       pop r16
        ret
+
+init_lut:
+       rjmp bmw224_init
+       rjmp bmw256_init
+c2h_lut:
+       rjmp bmw224_ctx2hash
+       rjmp bmw256_ctx2hash