]> git.cryptolib.org Git - avr-crypto-lib.git/blob - bmw/bmw_small.c
fixing some warnings (AES); simplifyning AES headers (now simply include "aes.h"...
[avr-crypto-lib.git] / bmw / bmw_small.c
1 /* bmw_small.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * \file    bmw_small.c
21  * \author  Daniel Otte
22  * \email   daniel.otte@rub.de
23  * \date    2009-04-27
24  * \license GPLv3 or later
25  *
26  */
27
28 #include <stdint.h>
29 #include <string.h>
30 #include <avr/pgmspace.h>
31 #include "bmw_small.h"
32
33
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))))
38
39
40 #define TWEAK   1
41 #if TWEAK
42 #  define BUG24   0
43 #else
44 #  define BUG24   1
45 #endif
46
47 #define F0_HACK 2
48
49 #define DEBUG 0
50
51 #ifndef F0_HACK
52 #  define F0_HACK 0
53 #endif
54
55 #if DEBUG
56  #include "cli.h"
57
58  void ctx_dump(const bmw_small_ctx_t* ctx){
59         uint8_t i;
60         cli_putstr_P(PSTR("\r\n==== ctx dump ===="));
61         for(i=0; i<16;++i){
62                 cli_putstr_P(PSTR("\r\n h["));
63                 cli_hexdump(&i, 1);
64                 cli_putstr_P(PSTR("] = "));
65                 cli_hexdump_rev(&(ctx->h[i]), 4);
66         }
67         cli_putstr_P(PSTR("\r\n counter = "));
68         cli_hexdump(&(ctx->counter), 4);
69  }
70
71  void dump_x(const uint32_t* q, uint8_t elements, char x){
72         uint8_t i;
73         cli_putstr_P(PSTR("\r\n==== "));
74         cli_putc(x);
75         cli_putstr_P(PSTR(" dump ===="));
76         for(i=0; i<elements;++i){
77                 cli_putstr_P(PSTR("\r\n "));
78                 cli_putc(x);
79                 cli_putstr_P(PSTR("["));
80                 cli_hexdump(&i, 1);
81                 cli_putstr_P(PSTR("] = "));
82                 cli_hexdump_rev(&(q[i]), 4);
83         }
84  }
85 #else
86  #define ctx_dump(x)
87  #define dump_x(a,b,c)
88 #endif
89
90 static
91 uint32_t bmw_small_s0(uint32_t x){
92         uint32_t r;
93         r =   SHR32(x, 1)
94                 ^ SHL32(x, 3)
95                 ^ ROTL32(x, 4)
96                 ^ ROTR32(x, 13);
97         return r;
98 }
99
100 static
101 uint32_t bmw_small_s1(uint32_t x){
102         uint32_t r;
103         r =   SHR32(x, 1)
104                 ^ SHL32(x, 2)
105                 ^ ROTL32(x, 8)
106                 ^ ROTR32(x, 9);
107         return r;
108 }
109
110 static
111 uint32_t bmw_small_s2(uint32_t x){
112         uint32_t r;
113         r =   SHR32(x, 2)
114                 ^ SHL32(x, 1)
115                 ^ ROTL32(x, 12)
116                 ^ ROTR32(x, 7);
117         return r;
118 }
119
120 static
121 uint32_t bmw_small_s3(uint32_t x){
122         uint32_t r;
123         r =   SHR32(x, 2)
124                 ^ SHL32(x, 2)
125                 ^ ROTL32(x, 15)
126                 ^ ROTR32(x, 3);
127         return r;
128 }
129
130 static
131 uint32_t bmw_small_s4(uint32_t x){
132         uint32_t r;
133         r =   SHR32(x, 1)
134                 ^ x;
135         return r;
136 }
137
138 static
139 uint32_t bmw_small_s5(uint32_t x){
140         uint32_t r;
141         r =   SHR32(x, 2)
142                 ^ x;
143         return r;
144 }
145
146 static
147 uint32_t bmw_small_r1(uint32_t x){
148         uint32_t r;
149         r =   ROTL32(x, 3);
150         return r;
151 }
152
153 static
154 uint32_t bmw_small_r2(uint32_t x){
155         uint32_t r;
156         r =   ROTL32(x, 7);
157         return r;
158 }
159
160 static
161 uint32_t bmw_small_r3(uint32_t x){
162         uint32_t r;
163         r =   ROTL32(x, 13);
164         return r;
165 }
166
167 static
168 uint32_t bmw_small_r4(uint32_t x){
169         uint32_t r;
170         r =   ROTL32(x, 16);
171         return r;
172 }
173
174 static
175 uint32_t bmw_small_r5(uint32_t x){
176         uint32_t r;
177         r =   ROTR32(x, 13);
178         return r;
179 }
180
181 static
182 uint32_t bmw_small_r6(uint32_t x){
183         uint32_t r;
184         r =   ROTR32(x, 9);
185         return r;
186 }
187
188 static
189 uint32_t bmw_small_r7(uint32_t x){
190         uint32_t r;
191         r =   ROTR32(x, 5);
192         return r;
193 }
194 /*
195 #define K 0x05555555L
196 static
197 uint32_t k_lut[] PROGMEM = {
198         16L*K, 17L*K, 18L*K, 19L*K, 20L*K, 21L*K, 22L*K, 23L*K,
199         24L*K, 25L*K, 26L*K, 27L*K, 28L*K, 29L*K, 30L*K, 31L*K
200 };
201 */
202 /* same as above but precomputed to avoid compiler warnings */
203
204 static
205 uint32_t k_lut[] PROGMEM = {
206         0x55555550L, 0x5aaaaaa5L, 0x5ffffffaL,
207         0x6555554fL, 0x6aaaaaa4L, 0x6ffffff9L,
208         0x7555554eL, 0x7aaaaaa3L, 0x7ffffff8L,
209         0x8555554dL, 0x8aaaaaa2L, 0x8ffffff7L,
210         0x9555554cL, 0x9aaaaaa1L, 0x9ffffff6L,
211         0xa555554bL };
212
213 static
214 uint32_t bmw_small_expand1(uint8_t j, const uint32_t* q, const void* m, const void* h){
215         uint32_t(*s[])(uint32_t) = {bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s0};
216         uint32_t r;
217         uint8_t i;
218         /* r = 0x05555555*(j+16); */
219
220 #if TWEAK
221         r = (   ROTL32(((uint32_t*)m)[j&0xf],      ((j+0)&0xf)+1  )
222                + ROTL32(((uint32_t*)m)[(j+3)&0xf],  ((j+3)&0xf)+1  )
223                - ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 )
224                + pgm_read_dword(k_lut+j)
225              ) ^ ((uint32_t*)h)[(j+7)&0xf];
226 #else
227         r = pgm_read_dword(k_lut+j);
228         r += ((uint32_t*)m)[j&0xf];
229         r += ((uint32_t*)m)[(j+3)&0xf];
230         r -= ((uint32_t*)m)[(j+10)&0xf];
231 #endif
232         for(i=0; i<16; ++i){
233                 r += s[i%4](q[j+i]);
234         }
235         return r;
236 }
237
238 static
239 uint32_t bmw_small_expand2(uint8_t j, const uint32_t* q, const void* m, const void* h){
240         uint32_t(*rf[])(uint32_t) = {bmw_small_r1, bmw_small_r2, bmw_small_r3,
241                                      bmw_small_r4, bmw_small_r5, bmw_small_r6,
242                                                              bmw_small_r7};
243         uint32_t r=0;
244         uint8_t i;
245         for(i=0; i<14; i+=2){
246                 r += q[j+i];
247         }
248         for(i=0; i<14; i+=2){
249                 r += rf[i/2](q[j+i+1]);
250         }
251 #if TWEAK
252         r += bmw_small_s4(q[j+14]);
253         r += bmw_small_s5(q[j+15]);
254 #else
255         r += bmw_small_s5(q[j+14]);
256         r += bmw_small_s4(q[j+15]);
257 #endif
258 #if TWEAK
259         r += (   ROTL32(((uint32_t*)m)[j&0xf],      ((j+0)&0xf)+1  )
260                + ROTL32(((uint32_t*)m)[(j+3)&0xf],  ((j+3)&0xf)+1  )
261                - ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 )
262                + pgm_read_dword(k_lut+j)
263              ) ^ ((uint32_t*)h)[(j+7)&0xf];
264 #else
265         r += pgm_read_dword(k_lut+j);
266         r += ((uint32_t*)m)[j&0xf];
267         r += ((uint32_t*)m)[(j+3)&0xf];
268         r -= ((uint32_t*)m)[(j+10)&0xf];
269 #endif
270         return r;
271 }
272
273 #if F0_HACK==2
274 /* to understand this implementation take a look at f0-opt-table.txt */
275 static uint16_t hack_table[5] PROGMEM = { 0x0311, 0xDDB3, 0x2A79, 0x07AA, 0x51C2 };
276 static uint8_t  offset_table[5] PROGMEM = { 4+16, 6+16, 9+16, 12+16, 13+16 };
277
278 static
279 void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){
280         uint16_t hack_reg;
281         uint8_t c,i,j;
282         uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2,
283                                    bmw_small_s3, bmw_small_s4 };
284         for(i=0; i<16; ++i){
285                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
286         }
287         dump_x(h, 16, 'T');
288         memset(q, 0, 4*16);
289         c=4;
290         do{
291                 i=15;
292                 j=pgm_read_byte(offset_table+c);
293                 hack_reg=pgm_read_word(&(hack_table[c]));
294                 do{
295                         if(hack_reg&1){
296                                 q[i]-= h[j&15];
297                         }else{
298                                 q[i]+= h[j&15];
299                         }
300                         --j;
301                         hack_reg>>= 1;
302                 }while(i--!=0);
303         }while(c--!=0);
304         dump_x(q, 16, 'W');
305         for(i=0; i<16; ++i){
306                 q[i] = s[i%5](q[i]);
307         }
308 #if TWEAK
309         for(i=0; i<16; ++i){
310                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
311         }
312         for(i=0; i<16; ++i){
313                 q[i] += h[(i+1)&0xf];
314         }
315 #endif
316 }
317 #endif /* F0_HACK==2*/
318
319 #if F0_HACK==1
320 static
321 uint8_t f0_lut[] PROGMEM = {
322          5<<1, ( 7<<1)+1, (10<<1)+0, (13<<1)+0, (14<<1)+0,
323          6<<1, ( 8<<1)+1, (11<<1)+0, (14<<1)+0, (15<<1)+1,
324          0<<1, ( 7<<1)+0, ( 9<<1)+0, (12<<1)+1, (15<<1)+0,
325          0<<1, ( 1<<1)+1, ( 8<<1)+0, (10<<1)+1, (13<<1)+0,
326          1<<1, ( 2<<1)+0, ( 9<<1)+0, (11<<1)+1, (14<<1)+1,
327          3<<1, ( 2<<1)+1, (10<<1)+0, (12<<1)+1, (15<<1)+0,
328          4<<1, ( 0<<1)+1, ( 3<<1)+1, (11<<1)+1, (13<<1)+0,
329          1<<1, ( 4<<1)+1, ( 5<<1)+1, (12<<1)+1, (14<<1)+1,
330          2<<1, ( 5<<1)+1, ( 6<<1)+1, (13<<1)+0, (15<<1)+1,
331          0<<1, ( 3<<1)+1, ( 6<<1)+0, ( 7<<1)+1, (14<<1)+0,
332          8<<1, ( 1<<1)+1, ( 4<<1)+1, ( 7<<1)+1, (15<<1)+0,
333          8<<1, ( 0<<1)+1, ( 2<<1)+1, ( 5<<1)+1, ( 9<<1)+0,
334          1<<1, ( 3<<1)+0, ( 6<<1)+1, ( 9<<1)+1, (10<<1)+0,
335          2<<1, ( 4<<1)+0, ( 7<<1)+0, (10<<1)+0, (11<<1)+0,
336          3<<1, ( 5<<1)+1, ( 8<<1)+0, (11<<1)+1, (12<<1)+1,
337         12<<1, ( 4<<1)+1, ( 6<<1)+1, ( 9<<1)+1, (13<<1)+0
338 };
339
340 static
341 void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){
342         uint8_t i,j=-1,v,sign,l=0;
343         uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2,
344                                    bmw_small_s3, bmw_small_s4 };
345         for(i=0; i<16; ++i){
346                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
347         }
348         dump_x(h, 16, 'T');
349         // memset(q, 0, 4*16);
350         for(i=0; i<5*16; ++i){
351                 v = pgm_read_byte(f0_lut+i);
352                 sign = v&1;
353                 v >>=1;
354                 if(i==l){
355                         j++;
356                         l+=5;
357                         q[j] = h[v];
358                         continue;
359                 }
360                 if(sign){
361                         q[j] -= h[v];
362                 }else{
363                         q[j] += h[v];
364                 }
365         }
366         dump_x(q, 16, 'W');
367         for(i=0; i<16; ++i){
368                 q[i] = s[i%5](q[i]);
369         }
370 #if TWEAK
371         for(i=0; i<16; ++i){
372                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
373         }
374         for(i=0; i<16; ++i){
375                 q[i] += h[(i+1)&0xf];
376         }
377 #endif /* TWEAK */
378 }
379 #endif /* F0_HACK==1 */
380
381 #if F0_HACK==0
382 static
383 void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){
384         uint8_t i;
385         uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2,
386                                    bmw_small_s3, bmw_small_s4 };
387         for(i=0; i<16; ++i){
388                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
389         }
390         dump_x(h, 16, 'T');
391         q[ 0] = (h[ 5] - h[ 7] + h[10] + h[13] + h[14]);
392         q[ 1] = (h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
393         q[ 2] = (h[ 0] + h[ 7] + h[ 9] - h[12] + h[15]);
394         q[ 3] = (h[ 0] - h[ 1] + h[ 8] - h[10] + h[13]);
395         q[ 4] = (h[ 1] + h[ 2] + h[ 9] - h[11] - h[14]);
396         q[ 5] = (h[ 3] - h[ 2] + h[10] - h[12] + h[15]);
397         q[ 6] = (h[ 4] - h[ 0] - h[ 3] - h[11] + h[13]);
398         q[ 7] = (h[ 1] - h[ 4] - h[ 5] - h[12] - h[14]);
399         q[ 8] = (h[ 2] - h[ 5] - h[ 6] + h[13] - h[15]);
400         q[ 9] = (h[ 0] - h[ 3] + h[ 6] - h[ 7] + h[14]);
401         q[10] = (h[ 8] - h[ 1] - h[ 4] - h[ 7] + h[15]);
402         q[11] = (h[ 8] - h[ 0] - h[ 2] - h[ 5] + h[ 9]);
403         q[12] = (h[ 1] + h[ 3] - h[ 6] - h[ 9] + h[10]);
404         q[13] = (h[ 2] + h[ 4] + h[ 7] + h[10] + h[11]);
405         q[14] = (h[ 3] - h[ 5] + h[ 8] - h[11] - h[12]);
406         q[15] = (h[12] - h[ 4] - h[ 6] - h[ 9] + h[13]);
407         dump_x(q, 16, 'W');
408         for(i=0; i<16; ++i){
409                 q[i] = s[i%5](q[i]);
410         }
411 #if TWEAK
412         for(i=0; i<16; ++i){
413                 ((uint32_t*)h)[i] ^= ((uint32_t*)m)[i];
414         }
415         for(i=0; i<16; ++i){
416                 q[i] += h[(i+1)&0xf];
417         }
418 #endif /* TWEAK */
419 }
420 #endif /* F0_HACK==0 */
421
422 static
423 void bmw_small_f1(uint32_t* q, const void* m, const void* h){
424         uint8_t i;
425         q[16] = bmw_small_expand1(0, q, m, h);
426         q[17] = bmw_small_expand1(1, q, m, h);
427         for(i=2; i<16; ++i){
428                 q[16+i] = bmw_small_expand2(i, q, m, h);
429         }
430 }
431
432 static
433 void bmw_small_f2(uint32_t* h, const uint32_t* q, const void* m){
434         uint32_t xl=0, xh;
435         uint8_t i;
436         for(i=16;i<24;++i){
437                 xl ^= q[i];
438         }
439         xh = xl;
440         for(i=24;i<32;++i){
441                 xh ^= q[i];
442         }
443 #if DEBUG
444         cli_putstr_P(PSTR("\r\n XL = "));
445         cli_hexdump_rev(&xl, 4);
446         cli_putstr_P(PSTR("\r\n XH = "));
447         cli_hexdump_rev(&xh, 4);
448 #endif
449         memcpy(h, m, 16*4);
450         h[0] ^= SHL32(xh, 5) ^ SHR32(q[16], 5);
451         h[1] ^= SHR32(xh, 7) ^ SHL32(q[17], 8);
452         h[2] ^= SHR32(xh, 5) ^ SHL32(q[18], 5);
453         h[3] ^= SHR32(xh, 1) ^ SHL32(q[19], 5);
454         h[4] ^= SHR32(xh, 3) ^ q[20];
455         h[5] ^= SHL32(xh, 6) ^ SHR32(q[21], 6);
456         h[6] ^= SHR32(xh, 4) ^ SHL32(q[22], 6);
457         h[7] ^= SHR32(xh,11) ^ SHL32(q[23], 2);
458         for(i=0; i<8; ++i){
459                 h[i] += xl ^ q[24+i] ^ q[i];
460         }
461         for(i=0; i<8; ++i){
462                 h[8+i] ^= xh ^ q[24+i];
463                 h[8+i] += ROTL32(h[(4+i)%8],i+9);
464         }
465         h[ 8] += SHL32(xl, 8) ^ q[23] ^ q[ 8];
466         h[ 9] += SHR32(xl, 6) ^ q[16] ^ q[ 9];
467         h[10] += SHL32(xl, 6) ^ q[17] ^ q[10];
468         h[11] += SHL32(xl, 4) ^ q[18] ^ q[11];
469         h[12] += SHR32(xl, 3) ^ q[19] ^ q[12];
470         h[13] += SHR32(xl, 4) ^ q[20] ^ q[13];
471         h[14] += SHR32(xl, 7) ^ q[21] ^ q[14];
472         h[15] += SHR32(xl, 2) ^ q[22] ^ q[15];
473 }
474
475 void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){
476         uint32_t q[32];
477         dump_x(block, 16, 'M');
478         bmw_small_f0(q, ctx->h, block);
479         dump_x(q, 16, 'Q');
480         bmw_small_f1(q, block, ctx->h);
481         dump_x(q, 32, 'Q');
482         bmw_small_f2(ctx->h, q, block);
483         ctx->counter += 1;
484         ctx_dump(ctx);
485 }
486
487 void bmw_small_lastBlock(bmw_small_ctx_t* ctx, const void* block, uint16_t length_b){
488         uint8_t buffer[64];
489         while(length_b >= BMW_SMALL_BLOCKSIZE){
490                 bmw_small_nextBlock(ctx, block);
491                 length_b -= BMW_SMALL_BLOCKSIZE;
492                 block = (uint8_t*)block + BMW_SMALL_BLOCKSIZE_B;
493         }
494         memset(buffer, 0, 64);
495         memcpy(buffer, block, (length_b+7)/8);
496         buffer[length_b>>3] |= 0x80 >> (length_b&0x07);
497         if(length_b+1>64*8-64){
498                 bmw_small_nextBlock(ctx, buffer);
499                 memset(buffer, 0, 64-8);
500                 ctx->counter -= 1;
501         }
502         *((uint64_t*)&(buffer[64-8])) = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b;
503         bmw_small_nextBlock(ctx, buffer);
504 #if TWEAK
505         uint8_t i;
506         uint32_t q[32];
507         memset(buffer, 0xaa, 64);
508         for(i=0; i<16;++i){
509                 buffer[i*4] = i+0xa0;
510         }
511 //      dump_x(buffer, 16, 'A');
512         dump_x(ctx->h, 16, 'M');
513         bmw_small_f0(q, (uint32_t*)buffer, ctx->h);
514         dump_x(buffer, 16, 'a');
515         dump_x(q, 16, 'Q');
516         bmw_small_f1(q, ctx->h, (uint32_t*)buffer);
517         dump_x(q, 32, 'Q');
518         bmw_small_f2((uint32_t*)buffer, q, ctx->h);
519         memcpy(ctx->h, buffer, 64);
520 #endif
521 }
522
523 void bmw224_init(bmw224_ctx_t* ctx){
524         uint8_t i;
525         ctx->h[0] = 0x00010203;
526         for(i=1; i<16; ++i){
527                 ctx->h[i] = ctx->h[i-1]+ 0x04040404;
528         }
529 #if BUG24
530         ctx->h[13] = 0x24353637;
531 #endif
532         ctx->counter=0;
533         ctx_dump(ctx);
534 }
535
536 void bmw256_init(bmw256_ctx_t* ctx){
537         uint8_t i;
538         ctx->h[0] = 0x40414243;
539         for(i=1; i<16; ++i){
540                 ctx->h[i] = ctx->h[i-1]+ 0x04040404;
541         }
542         ctx->counter=0;
543         ctx_dump(ctx);
544 }
545
546 void bmw224_nextBlock(bmw224_ctx_t* ctx, const void* block){
547         bmw_small_nextBlock(ctx, block);
548 }
549
550 void bmw256_nextBlock(bmw256_ctx_t* ctx, const void* block){
551         bmw_small_nextBlock(ctx, block);
552 }
553
554 void bmw224_lastBlock(bmw224_ctx_t* ctx, const void* block, uint16_t length_b){
555         bmw_small_lastBlock(ctx, block, length_b);
556 }
557
558 void bmw256_lastBlock(bmw256_ctx_t* ctx, const void* block, uint16_t length_b){
559         bmw_small_lastBlock(ctx, block, length_b);
560 }
561
562 void bmw224_ctx2hash(void* dest, const bmw224_ctx_t* ctx){
563         memcpy(dest, &(ctx->h[9]), 224/8);
564 }
565
566 void bmw256_ctx2hash(void* dest, const bmw256_ctx_t* ctx){
567         memcpy(dest, &(ctx->h[8]), 256/8);
568 }
569
570 void bmw224(void* dest, const void* msg, uint32_t length_b){
571         bmw_small_ctx_t ctx;
572         bmw224_init(&ctx);
573         while(length_b>=BMW_SMALL_BLOCKSIZE){
574                 bmw_small_nextBlock(&ctx, msg);
575                 length_b -= BMW_SMALL_BLOCKSIZE;
576                 msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
577         }
578         bmw_small_lastBlock(&ctx, msg, length_b);
579         bmw224_ctx2hash(dest, &ctx);
580 }
581
582 void bmw256(void* dest, const void* msg, uint32_t length_b){
583         bmw_small_ctx_t ctx;
584         bmw256_init(&ctx);
585         while(length_b>=BMW_SMALL_BLOCKSIZE){
586                 bmw_small_nextBlock(&ctx, msg);
587                 length_b -= BMW_SMALL_BLOCKSIZE;
588                 msg = (uint8_t*)msg + BMW_SMALL_BLOCKSIZE_B;
589         }
590         bmw_small_lastBlock(&ctx, msg, length_b);
591         bmw256_ctx2hash(dest, &ctx);
592 }
593