6 #include "twister-small.h"
8 /*********************************************************************/
10 void twister_small_init(twister_state_t* ctx, uint16_t hashsize_b){
11 memset(ctx->s, 0, 64);
12 ctx->counter=0xffffffffffffffffLL;
13 ctx->s[0][7] = hashsize_b>>8;
14 ctx->s[1][7] = hashsize_b&0xff;
15 ctx->length_counter_b = 0;
18 /*********************************************************************/
20 void twister_small_nextBlock(twister_state_t* ctx, const void* msg){
23 memcpy(tmp, ctx->s, 64);
24 twister_mini_round(ctx, msg);
25 msg = ((uint8_t*)msg) + 8;
26 twister_mini_round(ctx, msg);
27 msg = ((uint8_t*)msg) + 8;
28 twister_mini_round(ctx, msg);
29 msg = ((uint8_t*)msg) + 8;
30 memxor(ctx->s, tmp, 64);
33 memcpy(tmp, ctx->s, 64);
34 twister_mini_round(ctx, msg);
35 msg = ((uint8_t*)msg) + 8;
36 twister_mini_round(ctx, msg);
37 msg = ((uint8_t*)msg) + 8;
38 twister_mini_round(ctx, msg);
39 msg = ((uint8_t*)msg) + 8;
40 memxor(ctx->s, tmp, 64);
43 memcpy(tmp, ctx->s, 64);
44 twister_mini_round(ctx, msg);
45 msg = ((uint8_t*)msg) + 8;
46 twister_mini_round(ctx, msg);
47 twister_blank_round(ctx);
48 memxor(ctx->s, tmp, 64);
49 ctx->length_counter_b += 512;
52 /*********************************************************************/
54 void twister_small_lastBlock(twister_state_t* ctx, const void* msg, uint16_t length_b){
57 twister_small_nextBlock(ctx, msg);
58 msg = ((uint8_t*)msg)+64;
62 memcpy(tmp, msg, (length_b+7)/8);
63 tmp[length_b/8] |= 0x80 >> (length_b&0x07);
64 twister_small_nextBlock(ctx, tmp);
65 ctx->length_counter_b -= 512 - length_b;
67 twister_mini_round(ctx, &(ctx->length_counter_b));
68 twister_blank_round(ctx);
71 /*********************************************************************/
73 void twister_small_ctx2hash(void* dest, twister_state_t* ctx, uint16_t hashsize_b){
74 twister_ctx2hash(dest, ctx, hashsize_b);
77 /*********************************************************************/
78 /*********************************************************************/
80 #ifndef NO_TWISTER_256
82 void twister256_init(twister256_ctx_t* ctx){
83 twister_small_init(ctx, 256);
86 /*********************************************************************/
88 void twister256_nextBlock(twister256_ctx_t* ctx, const void* msg){
89 twister_small_nextBlock(ctx, msg);
92 /*********************************************************************/
94 void twister256_lastBlock(twister256_ctx_t* ctx, const void* msg, uint16_t length_b){
95 twister_small_lastBlock(ctx, msg, length_b);
98 /*********************************************************************/
100 void twister256_ctx2hash(void* dest, twister256_ctx_t* ctx){
101 twister_ctx2hash(dest, ctx, 256);
104 /*********************************************************************/
106 void twister256(void* dest, const void* msg, uint32_t msg_length_b){
108 twister_small_init(&ctx, 256);
109 while(msg_length_b >=512){
110 twister_small_nextBlock(&ctx, msg);
111 msg = (uint8_t*)msg + 512/8;
114 twister_small_lastBlock(&ctx, msg, msg_length_b);
115 twister_ctx2hash(dest, &ctx, 256);
118 /*********************************************************************/
122 /*********************************************************************/
123 /*********************************************************************/
125 #ifndef NO_TWISTER_224
127 void twister224_init(twister224_ctx_t* ctx){
128 twister_small_init(ctx, 224);
131 /*********************************************************************/
133 void twister224_nextBlock(twister224_ctx_t* ctx, const void* msg){
134 twister_small_nextBlock(ctx, msg);
137 /*********************************************************************/
139 void twister224_lastBlock(twister224_ctx_t* ctx, const void* msg, uint16_t length_b){
140 twister_small_lastBlock(ctx, msg, length_b);
143 /*********************************************************************/
145 void twister224_ctx2hash(void* dest, twister224_ctx_t* ctx){
146 twister_ctx2hash(dest, ctx, 224);
149 /*********************************************************************/
151 void twister224(void* dest, const void* msg, uint32_t msg_length_b){
153 twister_small_init(&ctx, 224);
154 while(msg_length_b >=512){
155 twister_small_nextBlock(&ctx, msg);
156 msg = (uint8_t*)msg + 512/8;
159 twister_small_lastBlock(&ctx, msg, msg_length_b);
160 twister_ctx2hash(dest, &ctx, 224);