3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * \email daniel.otte@rub.de
24 * \license GPLv3 or later
30 #include <avr/pgmspace.h>
31 #include "bmw_small.h"
34 #define SHL32(a,n) ((a)<<(n))
35 #define SHR32(a,n) ((a)>>(n))
36 #define ROTL32(a,n) (((a)<<(n))|((a)>>(32-(n))))
37 #define ROTR32(a,n) (((a)>>(n))|((a)<<(32-(n))))
45 void ctx_dump(const bmw_small_ctx_t* ctx){
47 cli_putstr_P(PSTR("\r\n==== ctx dump ===="));
49 cli_putstr_P(PSTR("\r\n h["));
51 cli_putstr_P(PSTR("] = "));
52 cli_hexdump_rev(&(ctx->h[i]), 4);
54 cli_putstr_P(PSTR("\r\n counter = "));
55 cli_hexdump(&(ctx->counter), 4);
58 void dump_x(const uint32_t* q, uint8_t elements, char x){
60 cli_putstr_P(PSTR("\r\n==== "));
62 cli_putstr_P(PSTR(" dump ===="));
63 for(i=0; i<elements;++i){
64 cli_putstr_P(PSTR("\r\n "));
66 cli_putstr_P(PSTR("["));
68 cli_putstr_P(PSTR("] = "));
69 cli_hexdump_rev(&(q[i]), 4);
78 void bmw224(void* dest, const void* msg, uint32_t length_b){
81 while(length_b>=BMW_SMALL_BLOCKSIZE){
82 bmw_small_nextBlock(&ctx, msg);
83 length_b -= BMW_SMALL_BLOCKSIZE;
84 msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
86 bmw_small_lastBlock(&ctx, msg, length_b);
87 bmw224_ctx2hash(dest, &ctx);
90 void bmw256(void* dest, const void* msg, uint32_t length_b){
93 while(length_b>=BMW_SMALL_BLOCKSIZE){
94 bmw_small_nextBlock(&ctx, msg);
95 length_b -= BMW_SMALL_BLOCKSIZE;
96 msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
98 bmw_small_lastBlock(&ctx, msg, length_b);
99 bmw256_ctx2hash(dest, &ctx);