2008-12-21 00:16:09 +00:00
|
|
|
/* twister-small.c */
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2010-11-01 22:55:41 +00:00
|
|
|
#include "memxor.h"
|
2008-12-21 00:16:09 +00:00
|
|
|
#include "twister-small.h"
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister_small_init(twister_state_t *ctx, uint16_t hashsize_b){
|
2008-12-22 03:19:07 +00:00
|
|
|
memset(ctx->s, 0, 64);
|
|
|
|
ctx->counter=0xffffffffffffffffLL;
|
|
|
|
ctx->s[0][7] = hashsize_b>>8;
|
|
|
|
ctx->s[1][7] = hashsize_b&0xff;
|
|
|
|
ctx->length_counter_b = 0;
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister_small_nextBlock(twister_state_t *ctx, const void *msg){
|
2008-12-21 00:16:09 +00:00
|
|
|
uint8_t tmp[8][8];
|
|
|
|
/* round 1 */
|
|
|
|
memcpy(tmp, ctx->s, 64);
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
2008-12-21 00:16:09 +00:00
|
|
|
memxor(ctx->s, tmp, 64);
|
2008-12-22 03:19:07 +00:00
|
|
|
|
2008-12-21 00:16:09 +00:00
|
|
|
/* round 2 */
|
|
|
|
memcpy(tmp, ctx->s, 64);
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
2008-12-21 00:16:09 +00:00
|
|
|
memxor(ctx->s, tmp, 64);
|
2008-12-22 03:19:07 +00:00
|
|
|
|
2008-12-21 00:16:09 +00:00
|
|
|
/* round 3 */
|
|
|
|
memcpy(tmp, ctx->s, 64);
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg) + 8;
|
|
|
|
twister_mini_round(ctx, msg);
|
|
|
|
twister_blank_round(ctx);
|
2008-12-21 00:16:09 +00:00
|
|
|
memxor(ctx->s, tmp, 64);
|
|
|
|
ctx->length_counter_b += 512;
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
2008-12-21 00:16:09 +00:00
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister_small_lastBlock(twister_state_t *ctx, const void *msg, uint16_t length_b){
|
2008-12-21 00:16:09 +00:00
|
|
|
uint8_t tmp[64];
|
2009-05-14 09:38:02 +00:00
|
|
|
while(length_b>=512){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_nextBlock(ctx, msg);
|
|
|
|
msg = ((uint8_t*)msg)+64;
|
|
|
|
length_b -= 512;
|
|
|
|
}
|
|
|
|
memset(tmp, 0, 64);
|
|
|
|
memcpy(tmp, msg, (length_b+7)/8);
|
|
|
|
tmp[length_b/8] |= 0x80 >> (length_b&0x07);
|
|
|
|
twister_small_nextBlock(ctx, tmp);
|
|
|
|
ctx->length_counter_b -= 512 - length_b;
|
2008-12-28 20:20:22 +00:00
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_mini_round(ctx, &(ctx->length_counter_b));
|
|
|
|
twister_blank_round(ctx);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister_small_ctx2hash(void *dest, twister_state_t *ctx, uint16_t hashsize_b){
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_ctx2hash(dest, ctx, hashsize_b);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2008-12-21 00:16:09 +00:00
|
|
|
#ifndef NO_TWISTER_256
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister256_init(twister256_ctx_t *ctx){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_init(ctx, 256);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister256_nextBlock(twister256_ctx_t *ctx, const void *msg){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_nextBlock(ctx, msg);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister256_lastBlock(twister256_ctx_t *ctx, const void *msg, uint16_t length_b){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_lastBlock(ctx, msg, length_b);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister256_ctx2hash(void *dest, twister256_ctx_t *ctx){
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_ctx2hash(dest, ctx, 256);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister256(void *dest, const void *msg, uint32_t msg_length_b){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_state_t ctx;
|
|
|
|
twister_small_init(&ctx, 256);
|
|
|
|
while(msg_length_b >=512){
|
|
|
|
twister_small_nextBlock(&ctx, msg);
|
|
|
|
msg = (uint8_t*)msg + 512/8;
|
|
|
|
msg_length_b -= 512;
|
|
|
|
}
|
|
|
|
twister_small_lastBlock(&ctx, msg, msg_length_b);
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_ctx2hash(dest, &ctx, 256);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2008-12-21 00:16:09 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2008-12-21 00:16:09 +00:00
|
|
|
#ifndef NO_TWISTER_224
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister224_init(twister224_ctx_t *ctx){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_init(ctx, 224);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister224_nextBlock(twister224_ctx_t *ctx, const void *msg){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_nextBlock(ctx, msg);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister224_lastBlock(twister224_ctx_t *ctx, const void *msg, uint16_t length_b){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_small_lastBlock(ctx, msg, length_b);
|
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister224_ctx2hash(void *dest, twister224_ctx_t *ctx){
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_ctx2hash(dest, ctx, 224);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 03:19:07 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
|
2013-02-17 09:44:36 +00:00
|
|
|
void twister224(void *dest, const void *msg, uint32_t msg_length_b){
|
2008-12-21 00:16:09 +00:00
|
|
|
twister_state_t ctx;
|
|
|
|
twister_small_init(&ctx, 224);
|
|
|
|
while(msg_length_b >=512){
|
|
|
|
twister_small_nextBlock(&ctx, msg);
|
|
|
|
msg = (uint8_t*)msg + 512/8;
|
|
|
|
msg_length_b -= 512;
|
|
|
|
}
|
|
|
|
twister_small_lastBlock(&ctx, msg, msg_length_b);
|
2008-12-22 03:19:07 +00:00
|
|
|
twister_ctx2hash(dest, &ctx, 224);
|
2008-12-21 00:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|