/* $Id: idea.c,v 1.10 1999/06/25 05:33:42 levitte Exp $ */

#include "gnu_extras.h"

#include <stdio.h>		/* Because some versions of OpenSSL need it */
#include <string.h>
#include <lib$routines.h>
#include <starlet.h>
#ifdef __GNUC__
#define __DECC
#endif
#include <openssl/idea.h>
#ifdef __GNUC__
#undef __DECC
#endif
#include "fish.h"
#include "ssh.h"
#include "util.h"
#include "fishmsg.h"

typedef struct {
    IDEA_KEY_SCHEDULE ks;
    unsigned char ivec[8];
} idea_state;

void ssh_idea_encrypt(unsigned char *in, unsigned char *out, long len,
    void *encryptstate_)
{
    idea_state *encryptstate = encryptstate_;
    int num = 0;

    idea_cfb64_encrypt(in, out, len, &(encryptstate->ks), encryptstate->ivec,
	&num, IDEA_ENCRYPT);
}

void ssh_idea_decrypt(unsigned char *in, unsigned char *out, long len,
    void *decryptstate_)
{
    idea_state *decryptstate = decryptstate_;
    int num = 0;

    idea_cfb64_encrypt(in, out, len, &(decryptstate->ks), decryptstate->ivec,
	&num, IDEA_DECRYPT);
}

void ssh_idea_clean(ssh_state *state)
{
    xfree(state->encryptstate);
    xfree(state->decryptstate);
    state->encrypt = NULL;
    state->decrypt = NULL;
    state->cryptclean = NULL;
}

void *ssh_idea_encryptstate(ssh_state *state, int keylen, Erf erf, void *erfp)
{
    idea_state *encryptstate = xmalloc(sizeof(idea_state));
    if (!encryptstate) {
	ssh_F_memfull();
	return NULL;
    }
    idea_set_encrypt_key(state->sesskey, &(encryptstate->ks));
    memset(encryptstate->ivec, 0, 8);

    return encryptstate;
}

void *ssh_idea_decryptstate(ssh_state *state, int keylen, Erf erf, void *erfp)
{
    return ssh_idea_encryptstate(state, keylen, erf, erfp);
}

/* Emacs local variables

Local variables:
eval: (set-c-style "BSD")
end:

*/
