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