#include <string.h>
#include "hash.h"
#include "ecurve.h"
#include "utils.h"

void hash1(char *ID, epoint *Q, epoint *PK_pub, big p, big h_1_big)
{
    // 计算hash值H_1(ID, R, PK_pub)
    //hash1(ID, Q, PK_pub)
    sha256 sh;
    char h_1[33] = {0};

    shs256_init(&sh);
    sha256_update_string(sh, ID, strlen(ID));
    sha256_update_point(sh, Q);
    sha256_update_point(sh, PK_pub);
    shs256_hash(&sh, h_1);

    bytes_to_big(32, h_1, h_1_big);
    power(h_1_big, 1, p, h_1_big); // mod p
}

void hash2(char *ID, epoint *X, big p, big h_2_big)
{
    // 计算hash值H_2(ID, X)
    sha256 sh;
    char h_2[33] = {0};

    shs256_init(&sh);
    sha256_update_string(sh, ID, strlen(ID));
    sha256_update_point(sh, X);
    shs256_hash(&sh, h_2);

    bytes_to_big(32, h_2, h_2_big);
    power(h_2_big, 1, p, h_2_big); // mod p
}

void hash3(
    char *ID,
    char *msg,
    epoint *Q,
    epoint *U,
    epoint *PK_pub,
    big p,
    big h_3_big
)
{
    sha256 sh;
    char h_3[33] = {0};

    shs256_init(&sh);
    sha256_update_string(sh, ID, strlen(ID));
    sha256_update_string(sh, msg, strlen(msg));
    sha256_update_point(sh, Q);
    sha256_update_point(sh, U);
    sha256_update_point(sh, PK_pub);
    shs256_hash(&sh, h_3);

    bytes_to_big(32, h_3, h_3_big);
    power(h_3_big, 1, p, h_3_big); // mod p
}
