예제 #1
0
void md_map_shone_state(unsigned char *state) {
	*(uint32_t *)(state) = util_conv_big(ctx.Intermediate_Hash[0]);
	*(uint32_t *)(state + 4) = util_conv_big(ctx.Intermediate_Hash[1]);
	*(uint32_t *)(state + 8) = util_conv_big(ctx.Intermediate_Hash[2]);
	*(uint32_t *)(state + 12) = util_conv_big(ctx.Intermediate_Hash[3]);
	*(uint32_t *)(state + 16) = util_conv_big(ctx.Intermediate_Hash[4]);
}
예제 #2
0
void md_kdf2(uint8_t *key, int key_len, const uint8_t *in,
		int in_len) {
	uint32_t i, j, d;
	uint8_t buffer[in_len + sizeof(uint32_t)];
	uint8_t t[key_len + MD_LEN];

	/* d = ceil(kLen/hLen). */
	d = CEIL(key_len, MD_LEN);
	memcpy(buffer, in, in_len);
	for (i = 1; i <= d; i++) {
		j = util_conv_big(i);
		/* c = integer_to_string(c, 4). */
		memcpy(buffer + in_len, &j, sizeof(uint32_t));
		/* t = t || hash(z || c). */
		md_map(t + (i - 1) * MD_LEN, buffer, in_len + sizeof(uint32_t));
	}
	memcpy(key, t, key_len);
}
예제 #3
0
/*
 * Computes the hash derivation function.
 *
 * param[out] out       - the result.
 * param[in] out_len    - the number of bytes to return.
 * param[in] in         - the input string.
 * param[in] in_len     - the number of bytes in the input.
 */
static void rand_hash(uint8_t *out, int out_len, uint8_t *in,
		int in_len) {
	uint32_t j = util_conv_big(8 * out_len);
	int len = CEIL(out_len, MD_LEN);
	uint8_t buf[1 + sizeof(uint32_t) + in_len], hash[MD_LEN];

	buf[0] = 1;
	memcpy(buf + 1, &j, sizeof(uint32_t));
	memcpy(buf + 1 + sizeof(uint32_t), in, in_len);

	for (int i = 0; i < len; i++) {
		/* h = Hash(counter || bits_to_return || input_string) */
		md_map(hash, buf, 1 + sizeof(uint32_t) + in_len);
		/* temp = temp || h */
		memcpy(out, hash, MIN(MD_LEN, out_len));
		out += MD_LEN;
		out_len -= MD_LEN;
		/* counter = counter + 1 */
		buf[0]++;
	}
}
예제 #4
0
void md_map_shone_mid(uint8_t *state, uint8_t *msg, int len) {
	SHA1Context ctx;
	uint8_t dummy[64 - MD_LEN_SHONE] = { 0 };

	if (SHA1Reset(&ctx) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}

	if (SHA1Input(&ctx, msg, len) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA1Input(&ctx, dummy, sizeof(dummy)) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}

	uint32_t t[5];
	for (int i = 0; i < 5; i++) {
		t[i] = util_conv_big(ctx.Intermediate_Hash[i]);
	}

	memcpy(state, t, sizeof(t));
}