#include <crypto/crypto.h>
#include <crypto/bc.h>

NTL_CLIENT


void AES :: PrettyPrint(std::ostream& tofile)
{
	tofile << "AES(keylen=" << keysize << ")";
}

ostring AES :: encrypt(const ostring& key, const ostring& mssg)
{
	if (key.size() != keysize || mssg.size() != blocklen)
		throw General_error();

	ostring x;
	int i;
	struct aes_ctx *ctx;
	
	x.resize(blocklen);

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

	aes_set_encrypt_key(ctx, keysize, key.data());
	aes_encrypt(ctx, blocklen, x.data(), mssg.data());

	free(ctx);
	return x;
}


ostring AES :: decrypt(const ostring& key, const ostring& mssg)
{
	if (key.size() != keysize || mssg.size() != blocklen)
		throw General_error();

        ostring x;
        int i;
        struct aes_ctx *ctx;

	x.resize(blocklen);

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

        aes_set_decrypt_key(ctx, keysize, key.data());
        aes_decrypt(ctx, blocklen, x.data(), mssg.data());

        free(ctx);
        return x;
}

