/*
 * QEMU Crypto hash algorithms
 *
 * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates
 * Copyright (c) 2015 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "qemu/osdep.h"

#include "crypto/init.h"
#include "crypto/hash.h"

#define INPUT_TEXT "Hiss hisss Hissss hiss Hiss hisss Hiss hiss"
#define INPUT_TEXT1 "Hiss hisss "
#define INPUT_TEXT2 "Hissss hiss "
#define INPUT_TEXT3 "Hiss hisss Hiss hiss"

#define OUTPUT_MD5 "628d206371563035ab8ef62f492bdec9"
#define OUTPUT_SHA1 "b2e74f26758a3a421e509cee045244b78753cc02"
#define OUTPUT_SHA224 "e2f7415aad33ef79f6516b0986d7175f" \
                      "9ca3389a85bf6cfed078737b"
#define OUTPUT_SHA256 "bc757abb0436586f392b437e5dd24096" \
                      "f7f224de6b74d4d86e2abc6121b160d0"
#define OUTPUT_SHA384 "887ce52efb4f46700376356583b7e279" \
                      "4f612bd024e4495087ddb946c448c69d" \
                      "56dbf7152a94a5e63a80f3ba9f0eed78"
#define OUTPUT_SHA512 "3a90d79638235ec6c4c11bebd84d83c0" \
                      "549bc1e84edc4b6ec7086487641256cb" \
                      "63b54e4cb2d2032b393994aa263c0dbb" \
                      "e00a9f2fe9ef6037352232a1eec55ee7"
#define OUTPUT_RIPEMD160 "f3d658fad3fdfb2b52c9369cf0d441249ddfa8a0"

#define OUTPUT_MD5_B64 "Yo0gY3FWMDWrjvYvSSveyQ=="
#define OUTPUT_SHA1_B64 "sudPJnWKOkIeUJzuBFJEt4dTzAI="
#define OUTPUT_SHA224_B64 "4vdBWq0z73n2UWsJhtcXX5yjOJqFv2z+0Hhzew=="
#define OUTPUT_SHA256_B64 "vHV6uwQ2WG85K0N+XdJAlvfyJN5rdNTYbiq8YSGxYNA="
#define OUTPUT_SHA384_B64 "iHzlLvtPRnADdjVlg7fieU9hK9Ak5ElQh925RsRI" \
                          "xp1W2/cVKpSl5jqA87qfDu14"
#define OUTPUT_SHA512_B64 "OpDXljgjXsbEwRvr2E2DwFSbwehO3Etuxwhkh2QS" \
                          "VstjtU5MstIDKzk5lKomPA274AqfL+nvYDc1IjKh" \
                          "7sVe5w=="
#define OUTPUT_RIPEMD160_B64 "89ZY+tP9+ytSyTac8NRBJJ3fqKA="

static const char *expected_outputs[] = {
    [QCRYPTO_HASH_ALGO_MD5] = OUTPUT_MD5,
    [QCRYPTO_HASH_ALGO_SHA1] = OUTPUT_SHA1,
    [QCRYPTO_HASH_ALGO_SHA224] = OUTPUT_SHA224,
    [QCRYPTO_HASH_ALGO_SHA256] = OUTPUT_SHA256,
    [QCRYPTO_HASH_ALGO_SHA384] = OUTPUT_SHA384,
    [QCRYPTO_HASH_ALGO_SHA512] = OUTPUT_SHA512,
    [QCRYPTO_HASH_ALGO_RIPEMD160] = OUTPUT_RIPEMD160,
};
static const char *expected_outputs_b64[] = {
    [QCRYPTO_HASH_ALGO_MD5] = OUTPUT_MD5_B64,
    [QCRYPTO_HASH_ALGO_SHA1] = OUTPUT_SHA1_B64,
    [QCRYPTO_HASH_ALGO_SHA224] = OUTPUT_SHA224_B64,
    [QCRYPTO_HASH_ALGO_SHA256] = OUTPUT_SHA256_B64,
    [QCRYPTO_HASH_ALGO_SHA384] = OUTPUT_SHA384_B64,
    [QCRYPTO_HASH_ALGO_SHA512] = OUTPUT_SHA512_B64,
    [QCRYPTO_HASH_ALGO_RIPEMD160] = OUTPUT_RIPEMD160_B64,
};
static const int expected_lens[] = {
    [QCRYPTO_HASH_ALGO_MD5] = 16,
    [QCRYPTO_HASH_ALGO_SHA1] = 20,
    [QCRYPTO_HASH_ALGO_SHA224] = 28,
    [QCRYPTO_HASH_ALGO_SHA256] = 32,
    [QCRYPTO_HASH_ALGO_SHA384] = 48,
    [QCRYPTO_HASH_ALGO_SHA512] = 64,
    [QCRYPTO_HASH_ALGO_RIPEMD160] = 20,
};

static const char hex[] = "0123456789abcdef";

/* Test with dynamic allocation */
static void test_hash_alloc(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        uint8_t *result = NULL;
        size_t resultlen = 0;
        int ret;
        size_t j;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        ret = qcrypto_hash_bytes(i,
                                 INPUT_TEXT,
                                 strlen(INPUT_TEXT),
                                 &result,
                                 &resultlen,
                                 &error_fatal);
        g_assert(ret == 0);
        g_assert(resultlen == expected_lens[i]);

        for (j = 0; j < resultlen; j++) {
            g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
            g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
        }
        g_free(result);
    }
}

/* Test with caller preallocating */
static void test_hash_prealloc(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        uint8_t *result, *origresult;
        size_t resultlen;
        int ret;
        size_t j;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        resultlen = expected_lens[i];
        origresult = result = g_new0(uint8_t, resultlen);

        ret = qcrypto_hash_bytes(i,
                                 INPUT_TEXT,
                                 strlen(INPUT_TEXT),
                                 &result,
                                 &resultlen,
                                 &error_fatal);
        g_assert(ret == 0);
        /* Validate that our pre-allocated pointer was not replaced */
        g_assert(result == origresult);
        g_assert(resultlen == expected_lens[i]);
        for (j = 0; j < resultlen; j++) {
            g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
            g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
        }
        g_free(result);
    }
}


/* Test with dynamic allocation */
static void test_hash_iov(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        struct iovec iov[3] = {
            { .iov_base = (char *)INPUT_TEXT1, .iov_len = strlen(INPUT_TEXT1) },
            { .iov_base = (char *)INPUT_TEXT2, .iov_len = strlen(INPUT_TEXT2) },
            { .iov_base = (char *)INPUT_TEXT3, .iov_len = strlen(INPUT_TEXT3) },
        };
        uint8_t *result = NULL;
        size_t resultlen = 0;
        int ret;
        size_t j;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        ret = qcrypto_hash_bytesv(i,
                                  iov, 3,
                                  &result,
                                  &resultlen,
                                  &error_fatal);
        g_assert(ret == 0);
        g_assert(resultlen == expected_lens[i]);
        for (j = 0; j < resultlen; j++) {
            g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
            g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
        }
        g_free(result);
    }
}


/* Test with printable hashing */
static void test_hash_digest(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        int ret;
        char *digest;
        size_t digestsize;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        digestsize = qcrypto_hash_digest_len(i);

        g_assert_cmpint(digestsize * 2, ==, strlen(expected_outputs[i]));

        ret = qcrypto_hash_digest(i,
                                  INPUT_TEXT,
                                  strlen(INPUT_TEXT),
                                  &digest,
                                  &error_fatal);
        g_assert(ret == 0);
        g_assert_cmpstr(digest, ==, expected_outputs[i]);
        g_free(digest);
    }
}

/* Test with base64 encoding */
static void test_hash_base64(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        int ret;
        char *digest;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        ret = qcrypto_hash_base64(i,
                                  INPUT_TEXT,
                                  strlen(INPUT_TEXT),
                                  &digest,
                                  &error_fatal);
        g_assert(ret == 0);
        g_assert_cmpstr(digest, ==, expected_outputs_b64[i]);
        g_free(digest);
    }
}

static void test_hash_accumulate(void)
{
    size_t i;

    for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
        g_autoptr(QCryptoHash) hash = NULL;
        struct iovec iov[] = {
            { .iov_base = (char *)INPUT_TEXT1, .iov_len = strlen(INPUT_TEXT1) },
            { .iov_base = (char *)INPUT_TEXT2, .iov_len = strlen(INPUT_TEXT2) },
            { .iov_base = (char *)INPUT_TEXT3, .iov_len = strlen(INPUT_TEXT3) },
        };
        g_autofree uint8_t *result = NULL;
        size_t resultlen = 0;
        int ret;
        size_t j;

        if (!qcrypto_hash_supports(i)) {
            continue;
        }

        hash = qcrypto_hash_new(i, &error_fatal);
        g_assert(hash != NULL);

        /* Add each iovec to the hash context separately */
        for (j = 0; j < G_N_ELEMENTS(iov); j++) {
            ret = qcrypto_hash_updatev(hash,
                                      &iov[j], 1,
                                      &error_fatal);

            g_assert(ret == 0);
        }

        ret = qcrypto_hash_finalize_bytes(hash, &result, &resultlen,
                                          &error_fatal);

        g_assert(ret == 0);
        g_assert(resultlen == expected_lens[i]);
        for (j = 0; j < resultlen; j++) {
            g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
            g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
        }
    }
}

int main(int argc, char **argv)
{
    int ret = qcrypto_init(&error_fatal);
    g_assert(ret == 0);

    g_test_init(&argc, &argv, NULL);
    g_test_add_func("/crypto/hash/iov", test_hash_iov);
    g_test_add_func("/crypto/hash/alloc", test_hash_alloc);
    g_test_add_func("/crypto/hash/prealloc", test_hash_prealloc);
    g_test_add_func("/crypto/hash/digest", test_hash_digest);
    g_test_add_func("/crypto/hash/base64", test_hash_base64);
    g_test_add_func("/crypto/hash/accumulate", test_hash_accumulate);
    return g_test_run();
}
