now BMW-small entirely in asm
This commit is contained in:
parent
f0c9ba379b
commit
58cc633be2
|
@ -2077,3 +2077,136 @@ bmw256_ctx2hash:
|
|||
dec r22
|
||||
brne 1b
|
||||
ret
|
||||
|
||||
/*******************************************************************************
|
||||
* 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){
|
||||
* bmw_small_nextBlock(&ctx, msg);
|
||||
* length_b -= BMW_SMALL_BLOCKSIZE;
|
||||
* msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
|
||||
* }
|
||||
* bmw_small_lastBlock(&ctx, msg, length_b);
|
||||
* bmw256_ctx2hash(dest, &ctx);
|
||||
* }
|
||||
*
|
||||
* param dest: r24:r25
|
||||
* param msg: r22:r23
|
||||
* param length_b: r18:r21
|
||||
*/
|
||||
ctx0 = 2
|
||||
ctx1 = 3
|
||||
msg0 = 4
|
||||
msg1 = 5
|
||||
len0 = 6
|
||||
len1 = 7
|
||||
len2 = 8
|
||||
len3 = 9
|
||||
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
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* 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){
|
||||
* bmw_small_nextBlock(&ctx, msg);
|
||||
* length_b -= BMW_SMALL_BLOCKSIZE;
|
||||
* msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
|
||||
* }
|
||||
* bmw_small_lastBlock(&ctx, msg, length_b);
|
||||
* bmw224_ctx2hash(dest, &ctx);
|
||||
* }
|
||||
*
|
||||
* param dest: r24:r25
|
||||
* param msg: r22:r23
|
||||
* param length_b: r18:r21
|
||||
*/
|
||||
ctx0 = 2
|
||||
ctx1 = 3
|
||||
msg0 = 4
|
||||
msg1 = 5
|
||||
len0 = 6
|
||||
len1 = 7
|
||||
len2 = 8
|
||||
len3 = 9
|
||||
dst0 = 10
|
||||
dst1 = 11
|
||||
.global bmw224
|
||||
bmw224:
|
||||
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 bmw224_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 bmw224_ctx2hash
|
||||
stack_free_large 64+4
|
||||
pop_range 2, 11
|
||||
ret
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
/* bmw_small.c */
|
||||
/*
|
||||
This file is part of the AVR-Crypto-Lib.
|
||||
Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* \file bmw_small.c
|
||||
* \author Daniel Otte
|
||||
* \email daniel.otte@rub.de
|
||||
* \date 2009-04-27
|
||||
* \license GPLv3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "bmw_small.h"
|
||||
|
||||
|
||||
#define SHL32(a,n) ((a)<<(n))
|
||||
#define SHR32(a,n) ((a)>>(n))
|
||||
#define ROTL32(a,n) (((a)<<(n))|((a)>>(32-(n))))
|
||||
#define ROTR32(a,n) (((a)>>(n))|((a)<<(32-(n))))
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
|
||||
#if DEBUG
|
||||
#include "cli.h"
|
||||
|
||||
void ctx_dump(const bmw_small_ctx_t* ctx){
|
||||
uint8_t i;
|
||||
cli_putstr_P(PSTR("\r\n==== ctx dump ===="));
|
||||
for(i=0; i<16;++i){
|
||||
cli_putstr_P(PSTR("\r\n h["));
|
||||
cli_hexdump(&i, 1);
|
||||
cli_putstr_P(PSTR("] = "));
|
||||
cli_hexdump_rev(&(ctx->h[i]), 4);
|
||||
}
|
||||
cli_putstr_P(PSTR("\r\n counter = "));
|
||||
cli_hexdump(&(ctx->counter), 4);
|
||||
}
|
||||
|
||||
void dump_x(const uint32_t* q, uint8_t elements, char x){
|
||||
uint8_t i;
|
||||
cli_putstr_P(PSTR("\r\n==== "));
|
||||
cli_putc(x);
|
||||
cli_putstr_P(PSTR(" dump ===="));
|
||||
for(i=0; i<elements;++i){
|
||||
cli_putstr_P(PSTR("\r\n "));
|
||||
cli_putc(x);
|
||||
cli_putstr_P(PSTR("["));
|
||||
cli_hexdump(&i, 1);
|
||||
cli_putstr_P(PSTR("] = "));
|
||||
cli_hexdump_rev(&(q[i]), 4);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define ctx_dump(x)
|
||||
#define dump_x(a,b,c)
|
||||
#endif
|
||||
|
||||
|
||||
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){
|
||||
bmw_small_nextBlock(&ctx, msg);
|
||||
length_b -= BMW_SMALL_BLOCKSIZE;
|
||||
msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
|
||||
}
|
||||
bmw_small_lastBlock(&ctx, msg, length_b);
|
||||
bmw224_ctx2hash(dest, &ctx);
|
||||
}
|
||||
|
||||
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){
|
||||
bmw_small_nextBlock(&ctx, msg);
|
||||
length_b -= BMW_SMALL_BLOCKSIZE;
|
||||
msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
|
||||
}
|
||||
bmw_small_lastBlock(&ctx, msg, length_b);
|
||||
bmw256_ctx2hash(dest, &ctx);
|
||||
}
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ ALGO_NAME := BMW
|
|||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := bmw/
|
||||
$(ALGO_NAME)_OBJ := bmw_small-asm.o bmw_small-cstub.o bmw_large.o
|
||||
$(ALGO_NAME)_OBJ := bmw_small-asm.o bmw_large.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-bmw-test.o hfal_bmw_small.o hfal_bmw_large.o $(CLI_STD) $(HFAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := test nessie
|
||||
$(ALGO_NAME)_PERFORMANCE_TEST := performance
|
||||
|
|
Loading…
Reference in New Issue