SASC
DVBSoftCAM

idea.h File Reference

Go to the source code of this file.

Classes

struct  idea_key_st

Defines

#define IDEA_INT   unsigned int
#define IDEA_ENCRYPT   1
#define IDEA_DECRYPT   0
#define IDEA_BLOCK   8
#define IDEA_KEY_LENGTH   16

Typedefs

typedef struct idea_key_st IDEA_KEY_SCHEDULE

Functions

const char * idea_options (void)
void idea_ecb_encrypt (const unsigned char *in, unsigned char *out, IDEA_KEY_SCHEDULE *ks)
void idea_set_encrypt_key (const unsigned char *key, IDEA_KEY_SCHEDULE *ks)
void idea_set_decrypt_key (IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk)
void idea_cbc_encrypt (const unsigned char *in, unsigned char *out, long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int enc)
void idea_cfb64_encrypt (const unsigned char *in, unsigned char *out, long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num, int enc)
void idea_ofb64_encrypt (const unsigned char *in, unsigned char *out, long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num)
void idea_encrypt (unsigned long *in, IDEA_KEY_SCHEDULE *ks)

Define Documentation

#define IDEA_BLOCK   8

Definition at line 74 of file idea.h.

#define IDEA_DECRYPT   0

Definition at line 72 of file idea.h.

#define IDEA_ENCRYPT   1

Definition at line 71 of file idea.h.

#define IDEA_INT   unsigned int

Definition at line 63 of file idea.h.

#define IDEA_KEY_LENGTH   16

Definition at line 75 of file idea.h.


Typedef Documentation


Function Documentation

void idea_cbc_encrypt ( const unsigned char *  in,
unsigned char *  out,
long  length,
IDEA_KEY_SCHEDULE *  ks,
unsigned char *  iv,
int  enc 
)

Definition at line 62 of file i_cbc.c.

References idea_encrypt(), l2n, l2nn, n2l, and n2ln.

Referenced by cIDEA::Decrypt(), and cIDEA::Encrypt().

        {
        register unsigned long tin0,tin1;
        register unsigned long tout0,tout1,xor0,xor1;
        register long l=length;
        unsigned long tin[2];

        if (encrypt)
                {
                n2l(iv,tout0);
                n2l(iv,tout1);
                iv-=8;
                for (l-=8; l>=0; l-=8)
                        {
                        n2l(in,tin0);
                        n2l(in,tin1);
                        tin0^=tout0;
                        tin1^=tout1;
                        tin[0]=tin0;
                        tin[1]=tin1;
                        idea_encrypt(tin,ks);
                        tout0=tin[0]; l2n(tout0,out);
                        tout1=tin[1]; l2n(tout1,out);
                        }
                if (l != -8)
                        {
                        n2ln(in,tin0,tin1,l+8);
                        tin0^=tout0;
                        tin1^=tout1;
                        tin[0]=tin0;
                        tin[1]=tin1;
                        idea_encrypt(tin,ks);
                        tout0=tin[0]; l2n(tout0,out);
                        tout1=tin[1]; l2n(tout1,out);
                        }
                l2n(tout0,iv);
                l2n(tout1,iv);
                }
        else
                {
                n2l(iv,xor0);
                n2l(iv,xor1);
                iv-=8;
                for (l-=8; l>=0; l-=8)
                        {
                        n2l(in,tin0); tin[0]=tin0;
                        n2l(in,tin1); tin[1]=tin1;
                        idea_encrypt(tin,ks);
                        tout0=tin[0]^xor0;
                        tout1=tin[1]^xor1;
                        l2n(tout0,out);
                        l2n(tout1,out);
                        xor0=tin0;
                        xor1=tin1;
                        }
                if (l != -8)
                        {
                        n2l(in,tin0); tin[0]=tin0;
                        n2l(in,tin1); tin[1]=tin1;
                        idea_encrypt(tin,ks);
                        tout0=tin[0]^xor0;
                        tout1=tin[1]^xor1;
                        l2nn(tout0,tout1,out,l+8);
                        xor0=tin0;
                        xor1=tin1;
                        }
                l2n(xor0,iv);
                l2n(xor1,iv);
                }
        tin0=tin1=tout0=tout1=xor0=xor1=0;
        tin[0]=tin[1]=0;
        }
void idea_cfb64_encrypt ( const unsigned char *  in,
unsigned char *  out,
long  length,
IDEA_KEY_SCHEDULE *  ks,
unsigned char *  iv,
int *  num,
int  enc 
)
void idea_ecb_encrypt ( const unsigned char *  in,
unsigned char *  out,
IDEA_KEY_SCHEDULE *  ks 
)

Definition at line 62 of file i_ecb.c.

References idea_encrypt(), l2n, and n2l.

Referenced by cIDEA::EcbEncrypt().

        {
        unsigned long l0,l1,d[2];

        n2l(in,l0); d[0]=l0;
        n2l(in,l1); d[1]=l1;
        idea_encrypt(d,ks);
        l0=d[0]; l2n(l0,out);
        l1=d[1]; l2n(l1,out);
        l0=l1=d[0]=d[1]=0;
        }
void idea_encrypt ( unsigned long *  in,
IDEA_KEY_SCHEDULE *  ks 
)

Definition at line 136 of file i_cbc.c.

References idea_key_st::data, E_IDEA, IDEA_INT, and idea_mul.

Referenced by idea_cbc_encrypt(), and idea_ecb_encrypt().

        {
        register IDEA_INT *p;
        register unsigned long x1,x2,x3,x4,t0,t1,ul;

        x2=d[0];
        x1=(x2>>16);
        x4=d[1];
        x3=(x4>>16);

        p= &(key->data[0][0]);

        E_IDEA(0);
        E_IDEA(1);
        E_IDEA(2);
        E_IDEA(3);
        E_IDEA(4);
        E_IDEA(5);
        E_IDEA(6);
        E_IDEA(7);

        x1&=0xffff;
        idea_mul(x1,x1,*p,ul); p++;

        t0= x3+ *(p++);
        t1= x2+ *(p++);

        x4&=0xffff;
        idea_mul(x4,x4,*p,ul);

        d[0]=(t0&0xffff)|((x1&0xffff)<<16);
        d[1]=(x4&0xffff)|((t1&0xffff)<<16);
        }
void idea_ofb64_encrypt ( const unsigned char *  in,
unsigned char *  out,
long  length,
IDEA_KEY_SCHEDULE *  ks,
unsigned char *  iv,
int *  num 
)
const char* idea_options ( void  )
void idea_set_decrypt_key ( IDEA_KEY_SCHEDULE *  ek,
IDEA_KEY_SCHEDULE *  dk 
)

Definition at line 97 of file i_skey.c.

References idea_key_st::data, IDEA_INT, and inverse().

Referenced by cIDEA::SetDecKey().

        {
        int r;
        register IDEA_INT *fp,*tp,t;

        tp= &(dk->data[0][0]);
        fp= &(ek->data[8][0]);
        for (r=0; r<9; r++)
                {
                *(tp++)=inverse(fp[0]);
                *(tp++)=((int)(0x10000L-fp[2])&0xffff);
                *(tp++)=((int)(0x10000L-fp[1])&0xffff);
                *(tp++)=inverse(fp[3]);
                if (r == 8) break;
                fp-=6;
                *(tp++)=fp[4];
                *(tp++)=fp[5];
                }

        tp= &(dk->data[0][0]);
        t=tp[1];
        tp[1]=tp[2];
        tp[2]=t;

        t=tp[49];
        tp[49]=tp[50];
        tp[50]=t;
        }
void idea_set_encrypt_key ( const unsigned char *  key,
IDEA_KEY_SCHEDULE *  ks 
)

Definition at line 63 of file i_skey.c.

References idea_key_st::data, i, IDEA_INT, and n2s.

Referenced by cIDEA::Decrypt(), cIDEA::Encrypt(), cIDEA::SetDecKey(), and cIDEA::SetEncKey().

        {
        int i;
        register IDEA_INT *kt,*kf,r0,r1,r2;

        kt= &(ks->data[0][0]);
        n2s(key,kt[0]); n2s(key,kt[1]); n2s(key,kt[2]); n2s(key,kt[3]);
        n2s(key,kt[4]); n2s(key,kt[5]); n2s(key,kt[6]); n2s(key,kt[7]);

        kf=kt;
        kt+=8;
        for (i=0; i<6; i++)
                {
                r2= kf[1];
                r1= kf[2];
                *(kt++)= ((r2<<9) | (r1>>7))&0xffff;
                r0= kf[3];
                *(kt++)= ((r1<<9) | (r0>>7))&0xffff;
                r1= kf[4];
                *(kt++)= ((r0<<9) | (r1>>7))&0xffff;
                r0= kf[5];
                *(kt++)= ((r1<<9) | (r0>>7))&0xffff;
                r1= kf[6];
                *(kt++)= ((r0<<9) | (r1>>7))&0xffff;
                r0= kf[7];
                *(kt++)= ((r1<<9) | (r0>>7))&0xffff;
                r1= kf[0];
                if (i >= 5) break;
                *(kt++)= ((r0<<9) | (r1>>7))&0xffff;
                *(kt++)= ((r1<<9) | (r2>>7))&0xffff;
                kf+=8;
                }
        }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines