#include <crypto/hash.h>

NTL_CLIENT


void SHA1 :: PrettyPrint(ostream& tofile)
{
	tofile << "Sha1(";
	if (outlen != SHA1_DIGEST_SIZE)
		tofile << "outlen=" << outlen;
	tofile << ")";
}

ostring SHA1 :: eval(const ostring& str)
{
        int i;
        ostring x;
        struct sha1_ctx *ctx = NULL;

	x.resize(outlen);

        ctx = (struct sha1_ctx*)malloc(sizeof(struct sha1_ctx));

        sha1_init(ctx);
        sha1_update(ctx, str.size(), (uint8_t *)str.data());
        sha1_digest(ctx, outlen, (uint8_t *)x.data());

        free(ctx);
        return x;
}


void SHA256 :: PrettyPrint(ostream& tofile)
{
	tofile << "Sha256(";
        if (outlen != SHA256_DIGEST_SIZE)
                tofile << "outlen=" << outlen;
        tofile << ")";
}

ostring SHA256 :: eval(const ostring& str)
{
        int i;
        ostring x;
        struct sha256_ctx *ctx = NULL;

        x.resize(outlen);

        ctx = (struct sha256_ctx*)malloc(sizeof(struct sha256_ctx));

        sha256_init(ctx);
        sha256_update(ctx, str.size(), (uint8_t *)str.data());
        sha256_digest(ctx, outlen, (uint8_t *)x.data());

        free(ctx);
        return x;
}


void MD5 :: PrettyPrint(ostream& tofile)
{
        tofile << "MD5(";
        if (outlen != MD5_DIGEST_SIZE)
                tofile << "outlen=" << outlen;
        tofile << ")";
}

ostring MD5 :: eval(const ostring& str)
{
	int i;
        ostring x;
        struct md5_ctx *ctx = NULL;

	x.resize(outlen);

        ctx = (struct md5_ctx*)malloc(sizeof(struct md5_ctx));

        md5_init(ctx);
        md5_update(ctx, str.size(), (uint8_t *)str.data());
        md5_digest(ctx, outlen, (uint8_t *)x.data());

        free(ctx);
        return x;
}

