示例#1
0
void skein512_init(skein512_ctx_t *ctx, uint16_t outsize_b){
	skein_config_t conf;
	uint8_t null[UBI512_BLOCKSIZE_B];
	memset(null, 0, UBI512_BLOCKSIZE_B);
	memset(&conf, 0, sizeof(skein_config_t));
	conf.schema[0] = 'S';
	conf.schema[1] = 'H';
	conf.schema[2] = 'A';
	conf.schema[3] = '3';
	conf.version = 1;
	conf.out_length = outsize_b;
	ctx->outsize_b = outsize_b;
	ubi512_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
	ubi512_lastBlock(&(ctx->ubictx), &conf, 256);
	ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
}
void testrun_stdtest_ubi512(uint16_t outsize){
	ubi512_ctx_t ctx;
	skein_config_t conf;
	uint64_t iv[8];
	uint8_t null[UBI512_BLOCKSIZE_B];
	
	cli_putstr_P(PSTR("\r\n\r\nTest vectors for UBI (512 bits):"));
	memset(&conf, 0, sizeof(skein_config_t));
	memset(null, 0, UBI512_BLOCKSIZE_B);
	ubi512_init(&ctx, null, UBI_TYPE_CFG);
	conf.schema[0] = 'S';
	conf.schema[1] = 'H';
	conf.schema[2] = 'A';
	conf.schema[3] = '3';
	conf.version = 1;
	conf.out_length = outsize;
	ubi512_lastBlock(&ctx, &conf, 256);
	ubi512_ctx2hash(iv, &ctx);
		
	cli_putstr_P(PSTR("\r\nIV: "));
	cli_hexdump_rev(&(iv[0]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[1]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[2]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[3]), 8);
	cli_putstr_P(PSTR("\r\n    "));
	cli_hexdump_rev(&(iv[4]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[5]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[6]), 8);
	cli_putstr_P(PSTR("    "));
	cli_hexdump_rev(&(iv[7]), 8);
}
示例#3
0
void skein512_ctx2hash(void *dest, skein512_ctx_t *ctx){
	ubi512_ctx_t uctx;
	uint16_t outsize_b;
	
	uint64_t counter=0;
	uint8_t outbuffer[UBI512_BLOCKSIZE_B];
	ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
	
	outsize_b = ctx->outsize_b;
	while(1){
		memcpy(&uctx, &(ctx->ubictx), sizeof(ubi512_ctx_t));
		ubi512_lastBlock(&uctx, &counter, 64);
		ubi512_ctx2hash(outbuffer, &uctx);
		if(outsize_b<=UBI512_BLOCKSIZE){
			memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
			break;
		}else{
			memcpy(dest, outbuffer, UBI512_BLOCKSIZE_B);
			dest = (uint8_t*)dest + UBI512_BLOCKSIZE_B;
			outsize_b -= UBI512_BLOCKSIZE;
			counter++;
		}
	}
}