diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-23 00:30:12 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-23 00:30:12 +0000 |
| commit | 6e425a9de8c003b5a733621a6b6730ec3cc902b8 (patch) | |
| tree | 314123bcab78ff295f38f85f31dc141e5fe22d15 /libinterp | |
| parent | 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (diff) | |
20061220
Diffstat (limited to 'libinterp')
| -rw-r--r-- | libinterp/ipint.c | 157 | ||||
| -rw-r--r-- | libinterp/keyring.h | 6 | ||||
| -rw-r--r-- | libinterp/runt.h | 39 |
3 files changed, 201 insertions, 1 deletions
diff --git a/libinterp/ipint.c b/libinterp/ipint.c index 61c577fa..b7cb8af2 100644 --- a/libinterp/ipint.c +++ b/libinterp/ipint.c @@ -490,6 +490,163 @@ IPint_shr(void *fp) *f->ret = newIPint(ret); } +static void +mpand(mpint *b, mpint *m, mpint *res) +{ + int i; + + res->sign = b->sign; + if(b->top == 0 || m->top == 0){ + res->top = 0; + return; + } + mpbits(res, b->top*Dbits); + res->top = b->top; + for(i = b->top; --i >= 0;){ + if(i < m->top) + res->p[i] = b->p[i] & m->p[i]; + else + res->p[i] = 0; + } + mpnorm(res); +} + +static void +mpor(mpint *b1, mpint *b2, mpint *res) +{ + mpint *t; + int i; + + if(b2->top > b1->top){ + t = b1; + b1 = b2; + b2 = t; + } + if(b1->top == 0){ + mpassign(b2, res); + return; + } + if(b2->top == 0){ + mpassign(b1, res); + return; + } + mpassign(b1, res); + for(i = b2->top; --i >= 0;) + res->p[i] |= b2->p[i]; + mpnorm(res); +} + +static void +mpxor(mpint *b1, mpint *b2, mpint *res) +{ + mpint *t; + int i; + + if(b2->top > b1->top){ + t = b1; + b1 = b2; + b2 = t; + } + if(b1->top == 0){ + mpassign(b2, res); + return; + } + if(b2->top == 0){ + mpassign(b1, res); + return; + } + mpassign(b1, res); + for(i = b2->top; --i >= 0;) + res->p[i] ^= b2->p[i]; + mpnorm(res); +} + +static void +mpnot(mpint *b1, mpint *res) +{ + int i; + + mpbits(res, Dbits*b1->top); + res->sign = 1; + res->top = b1->top; + for(i = res->top; --i >= 0;) + res->p[i] = ~b1->p[i]; + mpnorm(res); +} + +/* bits */ +void +IPint_and(void *fp) +{ + F_IPint_and *f; + BigInt ret; + + f = fp; + destroy(*f->ret); + *f->ret = H; + + if(f->i1 == H || f->i2 == H) + error(exNilref); + ret = mpnew(0); + if(ret != nil) + mpand(MP(f->i1), MP(f->i2), ret); + *f->ret = newIPint(ret); +} + +void +IPint_ori(void *fp) +{ + F_IPint_ori *f; + BigInt ret; + + f = fp; + destroy(*f->ret); + *f->ret = H; + + if(f->i1 == H || f->i2 == H) + error(exNilref); + ret = mpnew(0); + if(ret != nil) + mpor(MP(f->i1), MP(f->i2), ret); + *f->ret = newIPint(ret); +} + +void +IPint_xor(void *fp) +{ + F_IPint_xor *f; + BigInt ret; + + f = fp; + destroy(*f->ret); + *f->ret = H; + + if(f->i1 == H || f->i2 == H) + error(exNilref); + ret = mpnew(0); + if(ret != nil) + mpxor(MP(f->i1), MP(f->i2), ret); + *f->ret = newIPint(ret); +} + +void +IPint_not(void *fp) +{ + F_IPint_not *f; + BigInt ret; + + f = fp; + destroy(*f->ret); + *f->ret = H; + + if(f->i1 == H) + error(exNilref); + ret = mpnew(0); + if(ret != nil) + mpnot(MP(f->i1), ret); + *f->ret = newIPint(ret); +} + /* * return a random number between a and b */ diff --git a/libinterp/keyring.h b/libinterp/keyring.h index f62ac800..0bea5171 100644 --- a/libinterp/keyring.h +++ b/libinterp/keyring.h @@ -3,6 +3,7 @@ Runtab Keyringmodtab[]={ "IPint.add",0xa47c1b24,IPint_add,40,2,{0x0,0xc0,}, "aescbc",0xac616ba,Keyring_aescbc,48,2,{0x0,0xc0,}, "aessetup",0x44452583,Keyring_aessetup,40,2,{0x0,0xc0,}, + "IPint.and",0xa47c1b24,IPint_and,40,2,{0x0,0xc0,}, "auth",0x9c576bb,Keyring_auth,48,2,{0x0,0xc0,}, "IPint.b64toip",0xa803ee03,IPint_b64toip,40,2,{0x0,0x80,}, "IPint.bebytestoip",0x6fa90725,IPint_bebytestoip,40,2,{0x0,0x80,}, @@ -41,6 +42,8 @@ Runtab Keyringmodtab[]={ "md5",0x7656377,Keyring_md5,48,2,{0x0,0xb0,}, "IPint.mul",0xa47c1b24,IPint_mul,40,2,{0x0,0xc0,}, "IPint.neg",0x491fbd11,IPint_neg,40,2,{0x0,0x80,}, + "IPint.not",0x491fbd11,IPint_not,40,2,{0x0,0x80,}, + "IPint.ori",0xa47c1b24,IPint_ori,40,2,{0x0,0xc0,}, "pktoattr",0xfb4e61ba,Keyring_pktoattr,40,2,{0x0,0x80,}, "pktostr",0xfb4e61ba,Keyring_pktostr,40,2,{0x0,0x80,}, "putbytearray",0x7cfef557,Keyring_putbytearray,48,2,{0x0,0xc0,}, @@ -70,6 +73,7 @@ Runtab Keyringmodtab[]={ "verify",0x8b5b9f76,Keyring_verify,48,2,{0x0,0xe0,}, "verifym",0x8b5b9f76,Keyring_verifym,48,2,{0x0,0xe0,}, "writeauthinfo",0x5ba03002,Keyring_writeauthinfo,40,2,{0x0,0xc0,}, + "IPint.xor",0xa47c1b24,IPint_xor,40,2,{0x0,0xc0,}, 0 }; -#define Keyringmodlen 70 +#define Keyringmodlen 74 diff --git a/libinterp/runt.h b/libinterp/runt.h index f7577f6a..e6e30924 100644 --- a/libinterp/runt.h +++ b/libinterp/runt.h @@ -3076,6 +3076,16 @@ struct F_Keyring_aessetup Array* key; Array* ivec; }; +void IPint_and(void*); +typedef struct F_IPint_and F_IPint_and; +struct F_IPint_and +{ + WORD regs[NREG-1]; + Keyring_IPint** ret; + uchar temps[12]; + Keyring_IPint* i1; + Keyring_IPint* i2; +}; void Keyring_auth(void*); typedef struct F_Keyring_auth F_Keyring_auth; struct F_Keyring_auth @@ -3459,6 +3469,25 @@ struct F_IPint_neg uchar temps[12]; Keyring_IPint* i; }; +void IPint_not(void*); +typedef struct F_IPint_not F_IPint_not; +struct F_IPint_not +{ + WORD regs[NREG-1]; + Keyring_IPint** ret; + uchar temps[12]; + Keyring_IPint* i1; +}; +void IPint_ori(void*); +typedef struct F_IPint_ori F_IPint_ori; +struct F_IPint_ori +{ + WORD regs[NREG-1]; + Keyring_IPint** ret; + uchar temps[12]; + Keyring_IPint* i1; + Keyring_IPint* i2; +}; void Keyring_pktoattr(void*); typedef struct F_Keyring_pktoattr F_Keyring_pktoattr; struct F_Keyring_pktoattr @@ -3749,6 +3778,16 @@ struct F_Keyring_writeauthinfo String* filename; Keyring_Authinfo* info; }; +void IPint_xor(void*); +typedef struct F_IPint_xor F_IPint_xor; +struct F_IPint_xor +{ + WORD regs[NREG-1]; + Keyring_IPint** ret; + uchar temps[12]; + Keyring_IPint* i1; + Keyring_IPint* i2; +}; #define Keyring_PATH "$Keyring" #define Keyring_Encrypt 0 #define Keyring_Decrypt 1 |
