uif2iso-0.1.7a/0000755000175100017510000000000011131144316012175 5ustar margamargauif2iso-0.1.7a/README0000644000175100017510000000043011070704170013054 0ustar margamargauif2iso ------- A command-line tool for converting single and multipart UIF images to the ISO format. See file uif2iso.txt for more documentation. Released under the GNU GPL license. Contact: Luigi Auriemma Homepage: http://aluigi.org/mytoolz.htm#uif2iso uif2iso-0.1.7a/INSTALL0000644000175100017510000000012211070634120013220 0ustar margamargauif2iso ------- Standard make call: make -C src PREFIX=/usr/local all install uif2iso-0.1.7a/src/0000755000175100017510000000000011131144042012760 5ustar margamargauif2iso-0.1.7a/src/loki91.c0000644000175100017510000002307611130673334014256 0ustar margamarga/* Copyright (C) 2008,2009 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* * loki91.c - library routines for a 64 bit LOKI91 implementation * * Designed by Matthew Kwan and * Lawrence Brown * Modifications: * v2.0 - original set of code by mkwan 9/91 * v3.0 - support both LOKI89 & LOKI91 versions 10/92 lpb * * Copyright 1991 by Lawrence Brown and UNSW. ** Lawrence Brown has agreed to grant permission for this ** code to be used in the uif2iso tool, and for the provisions of the GPL2 to now apply to it. ** original code http://www.unsw.adfa.edu.au/~lpb/research/loki91/loki_book.shar * * nb: if this program is compiled on a little-endian machine (eg Vax) * #define LITTLE_ENDIAN * in order to enable the byte swapping routines * * if a detailed trace of LOKI91 function f is required for debugging * #define TRACE=n n=1 print blocks, n=2 print fn f also * n=3 print individual S-box calcs also * * these routines assume that the 8-byte char arrays used to pass * the 64-bit blocks fall on a word boundary, so that the blocks * may be read as longwords for efficiency reasons. If this is * not true, the load & save of the parameters will need changing. */ #include #include "loki.h" /* include Interface Specification header file */ #include "loki.i" /* include Interface Specification header file */ /* * perm32(out, in, perm) is the general permutation of a 32-bit input * block to a 32-bit output block, under the control of a * permutation array perm. Each element of perm specifies which * input bit is to be permuted to the output bit with the same * index as the array element. * * nb: to set bits in the output word, as mask with a single 1 in it is * used. On each step, the 1 is shifted into the next location */ #define MSB 0x80000000L /* MSB of 32-bit word */ void perm32(out, in , perm) Long *out; /* Output 32-bit block to be permuted */ Long *in; /* Input 32-bit block after permutation */ char perm[32]; /* Permutation array */ { Long mask = MSB; /* mask used to set bit in output */ register int i, o, b; /* input bit no, output bit no, value */ register char *p = perm; /* ptr to permutation array */ *out = 0; /* clear output block */ for (o=0; o<32; o++) { /* For each output bit position o */ i =(int)*p++; /* get input bit permuted to output o */ b = (*in >> i) & 01; /* value of input bit i */ if (b) /* If the input bit i is set */ *out |= mask; /* OR in mask to output i */ mask >>= 1; /* Shift mask to next bit */ } } /* * mult8(a, b, gen) - returns the product of two binary * strings a and b using the generator gen as the modulus * mult = a * b mod gen * gen generates a suitable Galois field in GF(2^8) */ #define SIZE 256 /* 256 elements in GF(2^8) */ short mult8(a, b, gen) short a, b; /* operands for multiply */ short gen; /* irreducible polynomial generating Galois Field */ { short product = 0; /* result of multiplication */ while(b != 0) { /* while multiplier is non-zero */ if (b & 01) product ^= a; /* add multiplicand if LSB of b set */ a <<= 1; /* shift multiplicand one place */ if (a >= SIZE) a ^= gen; /* and modulo reduce if needed */ b >>= 1; /* shift multiplier one place */ } return(product); } /* * exp8(base, exponent, gen) - returns the result of * exponentiation given the base, exponent, generator of GF, * exp = base ^ exp mod gen */ short exp8(base, exponent, gen) short base; /* base of exponentiation */ short exponent; /* exponent */ short gen; /* irreducible polynomial generating Galois Field */ { short accum = base; /* superincreasing sequence of base */ short result = 1; /* result of exponentiation */ if (base == 0) /* if zero base specified then */ return(0); /* the result is "0" if base = 0 */ while (exponent != 0) { /* repeat while exponent non-zero */ if (( exponent & 0x0001) == 0x0001) /* multiply if exp 1 */ result = mult8(result, accum, gen); exponent >>= 1; /* shift exponent to next digit */ accum = mult8(accum, accum, gen); /* & square */ } return(result); } /* * string specifying version and copyright message */ char *loki_lib_ver = "LOKI91 library v3.0, Copyright (C) 1991 Lawrence Brown & UNSW"; /* subkeys at the 16 rounds */ static Long f(); /* declare LOKI function f */ static short s(); /* declare LOKI S-box fn s */ /* * ROL12(b) - macro to rotate 32-bit block b left by 12 bits * ROL13(b) - macro to rotate 32-bit block b left by 13 bits */ #define ROL12(b) b = ((b << 12) | (b >> 20)); #define ROL13(b) b = ((b << 13) | (b >> 19)); /* * setlokikey(key) - save 64-bit key for use in encryptions & decryptions * and compute sub-keys using the key schedule */ void setlokikey(Long loki_subkeys[ROUNDS], char key[LOKIBLK]) { register int i; register Long KL, KR; #if TRACE >= 1 fprintf(stderr," keyinit(%08lx, %08lx)\n", ((Long *)key)[0], ((Long *)key)[1]); #endif KL = ((Long *)key)[0]; KR = ((Long *)key)[1]; for (i=0; i= 1 fprintf(stderr," enloki(%08lx, %08lx)\n", ((Long *)b)[0], ((Long *)b)[1]); #endif L = ((Long *)b)[0]; R = ((Long *)b)[1]; for (i=0; i= 1 fprintf(stderr," enloki returns %08lx, %08lx\n", ((Long *)b)[0], ((Long *)b)[1]); #endif } /* * deloki(b) - main LOKI91 decryption routine, this routine decrypts one * 64-bit block b using the LOKI91 algorithm with loki_subkeys * * Decryption uses the same algorithm as encryption, except that * the subkeys are used in reverse order. */ void deloki(Long loki_subkeys[ROUNDS], char b[LOKIBLK]) { register int i; register Long L, R; /* left & right data halves */ #if TRACE >= 1 fprintf(stderr," deloki(%08lx, %08lx)\n", ((Long *)b)[0], ((Long *)b)[1]); #endif L = ((Long *)b)[0]; /* LR = X XOR K */ R = ((Long *)b)[1]; for (i=ROUNDS; i>0; i-=2) { /* subkeys in reverse order */ L ^= f(R, loki_subkeys[i-1]); R ^= f(L, loki_subkeys[i-2]); } ((Long *)b)[0] = R; /* Y = LR XOR K */ ((Long *)b)[1] = L; #if TRACE >= 1 fprintf(stderr," deloki returns %08lx, %08lx\n", ((Long *)b)[0], ((Long *)b)[1]); #endif } /* * f(r, k) - is the complex non-linear LOKI function, whose output * is a complex function of both input data and sub-key. * * The data is XORed with the subkey, then expanded into 4 x 12-bit * values, which are fed into the S-boxes. The 4 x 8-bit outputs * from the S-boxes are permuted together to form the 32-bit value * which is returned. * * In this implementation the outputs from the S-boxes have been * pre-permuted and stored in lookup tables. */ #define MASK12 0x0fff /* 12 bit mask for expansion E */ static Long f(r, k) register Long r; /* Data value R(i-1) */ Long k; /* Key K(i) */ { Long a, b, c; /* 32 bit S-box output, & P output */ a = r ^ k; /* A = R(i-1) XOR K(i) */ /* want to use slow speed/small size version */ b = ((Long)s((a & MASK12)) ) | /* B = S(E(R(i-1))^K(i)) */ ((Long)s(((a >> 8) & MASK12)) << 8) | ((Long)s(((a >> 16) & MASK12)) << 16) | ((Long)s((((a >> 24) | (a << 8)) & MASK12)) << 24); perm32(&c, &b, P); /* C = P(S( E(R(i-1)) XOR K(i))) */ #if TRACE >= 2 /* If Tracing, dump A, K(i), and f(R(i-1),K(i)) */ fprintf(stderr," f(%08lx, %08lx) = P.S(%08lx) = P(%08lx) = %08lx\n", r, k, a, b, c); #endif return(c); /* f returns the result C */ } /* * s(i) - return S-box value for input i */ static short s(i) register Long i; /* return S-box value for input i */ { register short r, c, v, t; short exp8(); /* exponentiation routine for GF(2^8) */ r = ((i>>8) & 0xc) | (i & 0x3); /* row value-top 2 & bottom 2 */ c = (i>>2) & 0xff; /* column value-middle 8 bits */ t = (c + ((r * 17) ^ 0xff)) & 0xff; /* base value for Sfn */ v = exp8(t, sfn[r].exp, sfn[r].gen); /* Sfn[r] = t ^ exp mod gen */ #if TRACE >= 3 fprintf(stderr, " s(%lx=[%d,%d]) = %x sup %d mod %d = %x\n", i, r, c, t, sfn[r].exp, sfn[r].gen, v); #endif return(v); } uif2iso-0.1.7a/src/des.h0000644000175100017510000000746610752570054013737 0ustar margamarga/** * \file des.h */ #ifndef XYSSL_DES_H #define XYSSL_DES_H #define DES_ENCRYPT 0 #define DES_DECRYPT 1 /** * \brief DES context structure */ typedef struct { int mode; /*!< encrypt/decrypt */ unsigned long sk[32]; /*!< DES subkeys */ } des_context; /** * \brief Triple-DES context structure */ typedef struct { int mode; /*!< encrypt/decrypt */ unsigned long sk[96]; /*!< 3DES subkeys */ } des3_context; #ifdef __cplusplus extern "C" { #endif /** * \brief DES key schedule (56-bit, encryption) * * \param ctx DES context to be initialized * \param key 8-byte secret key */ void des_setkey_enc( des_context *ctx, unsigned char key[8] ); /** * \brief DES key schedule (56-bit, decryption) * * \param ctx DES context to be initialized * \param key 8-byte secret key */ void des_setkey_dec( des_context *ctx, unsigned char key[8] ); /** * \brief Triple-DES key schedule (112-bit, encryption) * * \param ctx 3DES context to be initialized * \param key 16-byte secret key */ void des3_set2key_enc( des3_context *ctx, unsigned char key[16] ); /** * \brief Triple-DES key schedule (112-bit, decryption) * * \param ctx 3DES context to be initialized * \param key 16-byte secret key */ void des3_set2key_dec( des3_context *ctx, unsigned char key[16] ); /** * \brief Triple-DES key schedule (168-bit, encryption) * * \param ctx 3DES context to be initialized * \param key 24-byte secret key */ void des3_set3key_enc( des3_context *ctx, unsigned char key[24] ); /** * \brief Triple-DES key schedule (168-bit, decryption) * * \param ctx 3DES context to be initialized * \param key 24-byte secret key */ void des3_set3key_dec( des3_context *ctx, unsigned char key[24] ); /** * \brief DES-ECB block encryption/decryption * * \param ctx DES context * \param input 64-bit input block * \param output 64-bit output block */ void des_crypt_ecb( des_context *ctx, unsigned char input[8], unsigned char output[8] ); /** * \brief DES-CBC buffer encryption/decryption * * \param ctx DES context * \param mode DES_ENCRYPT or DES_DECRYPT * \param length length of the input data * \param iv initialization vector (updated after use) * \param input buffer holding the input data * \param output buffer holding the output data */ void des_crypt_cbc( des_context *ctx, int mode, int length, unsigned char iv[8], unsigned char *input, unsigned char *output ); /** * \brief 3DES-ECB block encryption/decryption * * \param ctx 3DES context * \param input 64-bit input block * \param output 64-bit output block */ void des3_crypt_ecb( des3_context *ctx, unsigned char input[8], unsigned char output[8] ); /** * \brief 3DES-CBC buffer encryption/decryption * * \param ctx 3DES context * \param mode DES_ENCRYPT or DES_DECRYPT * \param length length of the input data * \param iv initialization vector (updated after use) * \param input buffer holding the input data * \param output buffer holding the output data */ void des3_crypt_cbc( des3_context *ctx, int mode, int length, unsigned char iv[8], unsigned char *input, unsigned char *output ); /* * \brief Checkup routine * * \return 0 if successful, or 1 if the test failed */ int des_self_test( int verbose ); #ifdef __cplusplus } #endif #endif /* des.h */ uif2iso-0.1.7a/src/loki.i0000644000175100017510000000362411070745410014105 0ustar margamarga/* * loki.i - contains the fixed permutation and substitution tables * for a 64 bit LOKI89 & LOKI91 implementations. * * Modifications: * v1.0 original tables Aug 1989 lpb * v2.0 add various speed/size versions Apr 1990 lpb * v2.1 install into RCS system for production control 5/90 lpb * v3.0 LOKI89 & LOKI91 now supported 10/92 lpb * * Author: Lawrence Brown Aug 1989 * Computer Science, UC UNSW, ADFA, Canberra, ACT 2600, Australia. * * Copyright 1989 by Lawrence Brown and UNSW. All rights reserved. * This program may not be sold or used as inducement to buy a * product without the written permission of the author. */ /* 32-bit permutation function P */ /* specifies which input bit is permuted to output bits */ /* 31 30 29 ... 2 1 0 respectively (ie in MSB to LSB order) */ char P[32] = { 31, 23, 15, 7, 30, 22, 14, 6, 29, 21, 13, 5, 28, 20, 12, 4, 27, 19, 11, 3, 26, 18, 10, 2, 25, 17, 9, 1, 24, 16, 8, 0 }; /* * sfn_desc - a desriptor table specifying which irreducible polynomial * and exponent is to be used for each of the 16 S functions in * the Loki S-box */ typedef struct { short gen; /* irreducible polynomial used in this field */ short exp; /* exponent used to generate this s function */ } sfn_desc; /* * sfn - the table specifying the irreducible polys & exponents used * in the Loki S-boxes for the Loki algorithm */ sfn_desc sfn[] = { { /* 101110111 */ 375, 31}, { /* 101111011 */ 379, 31}, { /* 110000111 */ 391, 31}, { /* 110001011 */ 395, 31}, { /* 110001101 */ 397, 31}, { /* 110011111 */ 415, 31}, { /* 110100011 */ 419, 31}, { /* 110101001 */ 425, 31}, { /* 110110001 */ 433, 31}, { /* 110111101 */ 445, 31}, { /* 111000011 */ 451, 31}, { /* 111001111 */ 463, 31}, { /* 111010111 */ 471, 31}, { /* 111011101 */ 477, 31}, { /* 111100111 */ 487, 31}, { /* 111110011 */ 499, 31}, { 00, 00} }; uif2iso-0.1.7a/src/seal.c0000644000175100017510000001346111070743700014065 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* SEAL */ #include #define ALG_OK 0 #define ALG_NOTOK 1 #define WORDS_PER_SEAL_CALL 1024 typedef struct { uint32_t t[520]; /* 512 rounded up to a multiple of 5 + 5*/ uint32_t s[265]; /* 256 rounded up to a multiple of 5 + 5*/ uint32_t r[20]; /* 16 rounded up to multiple of 5 */ uint32_t counter; /* 32-bit synch value. */ uint32_t ks_buf[WORDS_PER_SEAL_CALL]; int ks_pos; } seal_ctx; #define ROT2(x) (((x) >>2) | ((x) << 30)) #define ROT8(x) (((x) >>8) | ((x) << 24)) #define ROT9(x) (((x) >>9) | ((x) << 23)) #define ROT16(x) (((x) >> 16) | ((x) << 16)) #define ROT24(x) (((x) >> 24) | ((x) << 8)) #define ROT27(x) (((x) >> 27) | ((x) << 5)) #define WORD(cp) ((cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3])) #define F1(x, y, z) (((x) & (y)) | ((~(x)) & (z))) #define F2(x, y, z) ((x) ^ (y) ^ (z)) #define F3(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) #define F4(x, y, z) ((x) ^ (y) ^ (z)) int g(in,i,h) unsigned char *in; int i; uint32_t *h; { uint32_t h0,h1,h2,h3,h4,a,b,c,d,e,temp; unsigned char *kp; uint32_t w[80]; kp = in; h0 = WORD(kp); kp += 4; h1 = WORD(kp); kp += 4; h2 = WORD(kp); kp += 4; h3 = WORD(kp); kp += 4; h4 = WORD(kp); kp += 4; w[0] = i; for (i=1;i<16;i++) w[i] = 0; for (i=16;i<80;i++) w[i] = w[i-3]^w[i-8]^w[i-14]^w[i-16]; a = h0; b = h1; c = h2; d = h3; e = h4; for(i=0;i<20;i++) { temp = ROT27(a) + F1(b, c, d) + e + w[i] + 0xaa857398; e = d; d = c; c = ROT2(b); b = a; a = temp; } for (i=20;i<40;i++) { temp = ROT27(a) + F2(b, c, d) + e + w[i] + 0x938e7ffa; e = d; d = c; c = ROT2(b); b = a; a = temp; } for (i=40;i<60;i++) { temp = ROT27(a) + F3(b, c, d) + e + w[i] + 0x736a7d8a; e = d; d = c; c = ROT2(b); b = a; a = temp; } for (i=60;i<80;i++) { temp = ROT27(a) + F4(b, c, d) + e + w[i] + 0x837bba77; e = d; d = c; c = ROT2(b); b = a; a = temp; } h[0] = h0+a; h[1] = h1+b; h[2] = h2+c; h[3] = h3+d; h[4] = h4+e; return (ALG_OK); } int seal_init( seal_ctx *result, unsigned char *key ) { int i; uint32_t h[5]; for (i=0;i<510;i+=5) g(key, i/5, &(result->t[i])); /* horrible special case for the end */ g(key, 510/5, h); for(i=510;i<512;i++) result->t[i] = h[i-510]; /* 0x1000 mod 5 is +1, so have horrible special case for the start */ g(key, (-1+0x1000)/5, h); for (i=0;i<4;i++) result->s[i] = h[i+1]; for (i=4;i<254;i+=5) g(key, (i+0x1000)/5, &(result->s[i])); /* horrible special case for the end */ g(key, (254+0x1000)/5, h); for (i=254;i<256;i++) result->s[i] = h[i-254]; /* 0x2000 mod 5 is +2, so have horrible special case at the start */ g(key, (-2+0x2000)/5, h); for(i=0;i<3;i++) result->r[i] = h[i+2]; for (i=3;i<13;i+=5) g(key,(i+0x2000)/5,&(result->r[i])); /* horrible special case for the end */ g(key, (13+0x2000)/5, h); for (i=13;i<16;i++) result->r[i] = h[i-13]; return (ALG_OK); } int seal(seal_ctx *key, uint32_t in, uint32_t *out) { int i,j,l; uint32_t a,b,c,d,n1,n2,n3,n4,*wp; unsigned short p,q; wp = out; for (l=0;l<4;l++) { a = in ^ key->r[4*l]; b = ROT8(in) ^ key->r[4*l+1]; c = ROT16(in) ^ key->r[4*l+2]; d = ROT24(in) ^ key->r[4*l+3]; for (j=0;j<2;j++) { p = a & 0x7fc; b += key->t[p/4]; a = ROT9(a); p = b & 0x7fc; c += key->t[p/4]; b = ROT9(b); p = c & 0x7fc; d += key->t[p/4]; c = ROT9(c); p = d & 0x7fc; a += key->t[p/4]; d = ROT9(d); } n1 = d; n2 = b; n3 = a; n4 = c; p = a & 0x7fc; b += key->t[p/4]; a = ROT9(a); p = b & 0x7fc; c += key->t[p/4]; b = ROT9(b); p = c & 0x7fc; d += key->t[p/4]; c = ROT9(c); p = d & 0x7fc; a += key->t[p/4]; d = ROT9(d); for (i=0;i<64;i++) { p = a & 0x7fc; b += key->t[p/4]; a = ROT9(a); b ^= a; q = b & 0x7fc; c ^= key->t[q/4]; b = ROT9(b); c += b; p = (p+c) & 0x7fc; d += key->t[p/4]; c = ROT9(c); d ^= c; q = (q+d) & 0x7fc; a ^= key->t[q/4]; d = ROT9(d); a += d; p = (p+a) & 0x7fc; b ^= key->t[p/4]; a = ROT9(a); q = (q+b) & 0x7fc; c += key->t[q/4]; b = ROT9(b); p = (p+c) & 0x7fc; d ^= key->t[p/4]; c = ROT9(c); q = (q+d) & 0x7fc; a += key->t[q/4]; d = ROT9(d); *wp = b + key->s[4*i]; wp++; *wp = c ^ key->s[4*i+1]; wp++; *wp = d + key->s[4*i+2]; wp++; *wp = a ^ key->s[4*i+3]; wp++; if (i & 1) { a += n3; c += n4; } else { a += n1; c += n2; } } } return (ALG_OK); } /* Added call to refill ks_buf and reset counter and ks_pos. */ void seal_refill_buffer(seal_ctx *c){ seal(c,c->counter,c->ks_buf); c->counter++; c->ks_pos = 0; } void seal_key(seal_ctx *c, unsigned char *key){ seal_init(c,key); c->counter = 0; /* By default, init to zero. */ c->ks_pos = WORDS_PER_SEAL_CALL; /* Refill keystream buffer on next call. */ } /* This encrypts the next w words with SEAL. */ void seal_encrypt(seal_ctx *c, uint32_t *data_ptr, int w){ int i; for(i=0;iks_pos>=WORDS_PER_SEAL_CALL) seal_refill_buffer(c); data_ptr[i]^=c->ks_buf[c->ks_pos]; c->ks_pos++; } } void seal_decrypt(seal_ctx *c, uint32_t *data_ptr, int w) { seal_encrypt(c,data_ptr,w); } void seal_resynch(seal_ctx *c, uint32_t synch_word){ c->counter = synch_word; c->ks_pos = WORDS_PER_SEAL_CALL; } uif2iso-0.1.7a/src/Makefile0000644000175100017510000000214711104342434014431 0ustar margamarga# Copyright (C) 2007-2008 Luigi Auriemma # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # http://www.gnu.org/licenses/gpl.txt EXE = uif2iso CFLAGS += -O2 -s DESTDIR = prefix = /usr/local exec_prefix = $(prefix) bindir = $(exec_prefix)/bin BINDIR = $(DESTDIR)$(bindir) SRC = $(EXE).c LIBS = -lz des.c LzmaDec.c LIBSNEW = 3way.c blowfish.c dunno.c gost.c idea.c loki91.c rc5.c seal.c all: $(CC) $(SRC) $(CFLAGS) -o $(EXE) $(LIBS) $(CC) $(SRC) $(CFLAGS) -o $(EXE) $(LIBS) $(LIBSNEW) -DMAGICISO_IS_SHIT install: install -m 755 -d $(BINDIR) install -m 755 $(EXE) $(BINDIR) clean: rm -f *.o *.exe $(EXE) .PHONY: clean install # End of file uif2iso-0.1.7a/src/uif2iso.c0000644000175100017510000012145011104345560014517 0ustar margamarga/* Copyright (C) 2007,2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ #define _LARGE_FILES // if it's not supported the tool will work #define __USE_LARGEFILE64 // without support for large files #define __USE_FILE_OFFSET64 #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include "des.h" #include "LzmaDec.h" #ifdef __DJGPP__ // thanx to Robert Riebisch http://www.bttr-software.de #define NOLFS char **__crt0_glob_function (char *arg) { return 0; } void __crt0_load_environment_file (char *progname) { } #endif #ifdef WIN32 #include HWND mywnd; char *get_file(void); char *put_file(char *suggested); #else #define stricmp strcasecmp #endif typedef uint8_t u8; typedef uint16_t u16; typedef int32_t i32; typedef uint32_t u32; typedef int64_t i64; typedef uint64_t u64; #define VER "0.1.7" #define BBIS_SIGN 0x73696262 #define BLHR_SIGN 0x72686c62 #define BSDR_SIGN 0x72647362 #define BLMS_SIGN 0x736d6c62 #define BLSS_SIGN 0x73736c62 #define OUT_ISO 0 #define OUT_CUE 1 #define OUT_MDS 2 #define OUT_CCD 3 #define OUT_NRG 4 #define CREATECUE // creates an additional and "experimental" CUE file which can be used also on systems where are not available programs for the other formats #define NRGFIX // calls nrg_truncate at the end of the process #define PRINTF64(x) (u32)(((x) >> 32) & 0xffffffff), (u32)((x) & 0xffffffff) // I64x, llx? blah #if defined(_LARGE_FILES) #if defined(__APPLE__) #define fseek fseeko #define ftell ftello #elif defined(__FreeBSD__) #elif !defined(NOLFS) // use -DNOLFS if this tool can't be compiled on your OS! #define off_t off64_t #define fopen fopen64 #define fseek fseeko64 #define ftell ftello64 #endif #endif #pragma pack(1) typedef struct { u8 id[4]; u32 size; } nrg_chunk_t; typedef struct { u32 sign; // blhr u32 size; // size of the data plus ver and num u32 compressed; // compressed data u32 num; // number of blhr_data structures } blhr_t; typedef struct { u64 offset; // input offset u32 zsize; // block size u32 sector; // where to place the output u32 size; // size in sectors! u32 type; // type } blhr_data_t; typedef struct { u32 sign; // bbis u32 bbis_size; // ignored, probably the size of the structure u16 ver; // version, 1 u16 image_type; // 8 for ISO, 9 for mixed u16 unknown1; // ??? u16 padding; // ignored u32 sectors; // number of sectors of the ISO u32 sectorsz; // CD use sectors and this is the size of them (chunks) u32 lastdiff; // almost ignored u64 blhr; // where is located the blhr header u32 blhrbbissz; // total size of the blhr and bbis headers u8 hash[16]; // hash, used with passwords u8 key1; u8 key2; u8 key3; u8 key4; u32 unknown4; // ignored } bbis_t; #pragma pack() int endian; void myfree(u8 **mem); u8 *path2fname(u8 *path); u8 *frames2time(u64 num); void nrg2cue(FILE *fd, u64 nrgoff, u8 *fileo); void magiciso_is_invalid(FILE *fd, u64 nrgoff, u8 *fileo); void nrg_truncate(u8 *fileo, int secsz); u8 *blhr_unzip(FILE *fd, z_stream *z, CLzmaDec *lzma, des_context *des_ctx, u32 zsize, u32 unzsize, int compressed); u8 *change_ext(u8 *fname, u8 *ext); FILE *open_file(u8 *fname, int write); int blms2cue(FILE *fd, u8 *fname, u8 *blms, int blms_len); void uif_crypt_key(des_context **des_ctx, u8 *key, u8 *pwd); void uif_crypt(des_context *des_ctx, u8 *data, int size); u8 *show_hash(u8 *hash); void myalloc(u8 **data, unsigned wantsize, unsigned *currsize); void myfr(FILE *fd, void *data, unsigned size); void myfw(FILE *fd, void *data, unsigned size); u32 unlzma(CLzmaDec *lzma, u8 *in, u32 insz, u8 *out, u32 outsz); u32 unzip(z_stream *z, u8 *in, u32 insz, u8 *out, u32 outsz); void l2n_blhr(blhr_t *p); void l2n_blhr_data(blhr_data_t *p); void l2n_bbis(bbis_t *p); void l2n_16(u16 *num); // from little endian to number void l2n_32(u32 *num); void l2n_64(u64 *num); void b2n_16(u16 *num); // from big endian to number void b2n_32(u32 *num); void b2n_64(u64 *num); int getxx(u8 *data, u64 *ret, int bits, int intnet); int putxx(u8 *data, u64 num, int bits, int intnet); void std_err(void); int fgetz(u8 *data, int size, FILE *fd); void myexit(void); #include "magiciso_is_shit.h" static void *SzAlloc(void *p, size_t size) { return(malloc(size)); } static void SzFree(void *p, void *address) { free(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; magiciso_is_shit_ctx_t *shit_key_blhr = NULL, *shit_key_data = NULL; static const u8 *fixedkeys[] = { "FAngS)snOt32", "AglEy29TarsI;", "bum87OrYx*THeCa", "ARMy67sabot&", "FoOTs:blaZe70", "panIc+elD%self79", "Usnea*hest98", "apex(TUft!BLOKE70", "sword18rEpP}", "ARb10naVY=Rouse", "PAIR18gAG:swAYs", "gums}Box73yANg", "naVal45drain]", "Cams42hEt83faiLs)", "rIaNt$Notch5", "ExaCT&art*MEteS47", NULL }; int main(int argc, char *argv[]) { des_context *des_ctx = NULL; CLzmaDec *lzma = NULL; z_stream *z = NULL; blhr_data_t *blhr_data; blhr_t blhr, blms, // both blms and blss have a structure very similar to blhr so I have decided blss; // to use the same type for avoiding to create other functions bbis_t bbis; FILE *fdi = NULL, *fdo = NULL, *fdx = NULL; u64 file_size, tmp, tot; u32 i, insz, outsz, lastdiff = 0; int outtype = OUT_ISO; u8 ans[130], // password is max 31 chars pwdkey[32], // password is max 31 chars tmphash[16], *blms_data = NULL, *blss_data = NULL, *outext = NULL, *filei = NULL, *fileo = NULL, *filec = NULL, *in = NULL, *out = NULL, *p; setbuf(stdout, NULL); fputs("\n" "UIF2ISO "VER"\n" "by Luigi Auriemma\n" "e-mail: aluigi@autistici.org\n" "web: aluigi.org\n" "\n", stdout); endian = 1; // big endian if(*(char *)&endian) endian = 0; // little endian #ifdef WIN32 mywnd = GetForegroundWindow(); if(GetWindowLong(mywnd, GWL_WNDPROC)) { p = argv[1]; argv = malloc(sizeof(char *) * 3); if(argc < 2) { argv[1] = get_file(); } else { argv[1] = p; } argv[2] = put_file(argv[1]); argc = 3; } #endif if(argc < 3) { printf("\n" "Usage: %s \n" "\n" "The output ISO,CUE/BIN,MDS/MDS,CCD,NRG extension is choosed by this tool\n" "\n", argv[0]); myexit(); } filei = argv[1]; fileo = argv[2]; fdi = open_file(filei, 0); fseek(fdi, 0, SEEK_END); file_size = ftell(fdi); if(fseek(fdi, file_size - sizeof(bbis), SEEK_SET)) { if(((file_size - sizeof(bbis)) > 0x7fffffff) && ((file_size - sizeof(bbis)) < file_size)) printf(" an error here means that your exe has no full LARGE_FILES 64 bit support!\n"); std_err(); } myfr(fdi, &bbis, sizeof(bbis)); redo_bbis: l2n_bbis(&bbis); if(bbis.sign != BBIS_SIGN) { printf("\nError: wrong bbis signature (%08x)\n", bbis.sign); myexit(); } if(des_ctx) bbis.blhr += sizeof(bbis) + 8; printf("\n" " file size %08x%08x\n" " version %hu\n" " image type %hu\n" " padding %hu\n" " sectors %u\n" " sectors size %u\n" " blhr offset %08x%08x\n" " blhr size %u\n" " hash %s\n" " others %08x %08x %02x %02x %02x %02x %08x\n" "\n", PRINTF64(file_size), bbis.ver, bbis.image_type, bbis.padding, bbis.sectors, bbis.sectorsz, PRINTF64(bbis.blhr), bbis.blhrbbissz, show_hash(bbis.hash), bbis.bbis_size, bbis.lastdiff, bbis.key1, bbis.key2, bbis.key3, bbis.key4, bbis.unknown4); if((bbis.ver < 2) || ((bbis.key2 != 2) && (bbis.key1 > 0x10))) { printf("- disable any encryption\n"); bbis.key1 = 0; } if(bbis.key2 == 2) { printf("- enable magiciso_is_shit encryption\n"); shit_key_blhr = calloc(1, sizeof(magiciso_is_shit_ctx_t)); shit_key_data = calloc(1, sizeof(magiciso_is_shit_ctx_t)); if(!shit_key_blhr || !shit_key_data) std_err(); shit_key_blhr->flag = (bbis.key3 != 1) ? 0xff : bbis.key1; magiciso_is_shit_key(shit_key_blhr, bbis.key3); shit_key_data->flag = (bbis.key3 != 0x0f) ? bbis.key1 : 0; magiciso_is_shit_key(shit_key_data, bbis.key3); } else if(bbis.key1) { printf("- enable fixedkey encryption\n"); uif_crypt_key(&des_ctx, pwdkey, (u8 *)fixedkeys[(bbis.key1 - 1) & 0x0f]); des_setkey_dec(des_ctx, pwdkey); } if(fseek(fdi, bbis.blhr, SEEK_SET)) std_err(); myfr(fdi, &blhr, sizeof(blhr)); l2n_blhr(&blhr); if(blhr.sign != BLHR_SIGN) { if(blhr.sign == BSDR_SIGN) { printf("- the input file is protected by password, insert it: "); fgetz(ans, sizeof(ans), stdin); if(strlen(ans) > 31) ans[31] = 0; uif_crypt_key(&des_ctx, pwdkey, ans); des_setkey_dec(des_ctx, pwdkey); if(blhr.size != sizeof(bbis)) { printf("- Alert: the size of the bbis struct and the one specified by bsdr don't match\n"); } fseek(fdi, -8, SEEK_CUR); memcpy(tmphash, bbis.hash, sizeof(bbis.hash)); myfr(fdi, &bbis, sizeof(bbis)); uif_crypt(des_ctx, (u8 *)&bbis, sizeof(bbis)); memcpy(bbis.hash, tmphash, sizeof(bbis.hash)); goto redo_bbis; } else { printf("\nError: wrong blhr signature (%08x)\n", blhr.sign); } myexit(); } if(bbis.ver < 3) { z = malloc(sizeof(z_stream)); if(!z) std_err(); z->zalloc = (alloc_func)0; z->zfree = (free_func)0; z->opaque = (voidpf)0; if(inflateInit2(z, 15)) { printf("\nError: zlib initialization error\n"); myexit(); } } else { lzma = malloc(sizeof(CLzmaDec)); if(!lzma) std_err(); LzmaDec_Construct(lzma); } blhr_data = (blhr_data_t *)blhr_unzip(fdi, z, lzma, des_ctx, blhr.size - 8, sizeof(blhr_data_t) * blhr.num, blhr.compressed); if(bbis.image_type == 8) { // nothing to do } else if(bbis.image_type == 9) { printf("- raw or mixed type image\n"); myfr(fdi, &blms, sizeof(blms)); l2n_blhr(&blms); if(blms.sign != BLMS_SIGN) { printf("- Alert: wrong blms signature (%08x)\n", blms.sign); } else { blms_data = blhr_unzip(fdi, z, lzma, des_ctx, blms.size - 8, blms.num, blms.compressed); myfr(fdi, &blss, sizeof(blss)); myfr(fdi, &outtype, 4); l2n_blhr(&blss); l2n_32(&outtype); if(blss.sign != BLSS_SIGN) { printf("- Alert: wrong blss signature (%08x)\n", blss.sign); } else { if(blss.num) { blss_data = blhr_unzip(fdi, z, lzma, des_ctx, blss.size - 12, blss.num, blss.compressed); } } } } else { printf("- Alert: this type of image (%hu) is not supported by this tool, I try as ISO\n", bbis.image_type); } in = out = NULL; insz = outsz = 0; tot = 0; switch(outtype) { case OUT_ISO: { printf("- ISO output image format\n"); outext = ".iso"; break; } case OUT_CUE: { printf("- BIN/CUE output image format\n"); outext = ".bin"; break; } case OUT_MDS: { printf("- MDS output image format\n"); outext = ".mdf"; break; } case OUT_CCD: { printf("- CCD (CloneCD) output image format\n"); outext = ".img"; break; } case OUT_NRG: { printf("- NRG (Nero v2) output image format\n"); outext = ".nrg"; break; } default: { printf("\nError: the output image %u is not supported by this tool, contact me\n", outtype); myexit(); break; } } fileo = change_ext(fileo, outext); fdo = open_file(fileo, 1); #ifdef CREATECUE if(outtype != OUT_ISO) { // I generate a CUE file in ANY case for maximum compatibility printf("- generate an \"experimental\" CUE file for more compatibility on various systems\n"); filec = change_ext(fileo, "_uif2iso.cue"); fdx = open_file(filec, 1); blms2cue(fdx, path2fname(fileo), blms_data, blms.num); fclose(fdx); myfree(&filec); } #endif if(blss_data) { switch(outtype) { case OUT_ISO: { break; } case OUT_CUE: { filec = change_ext(fileo, ".cue"); fdx = open_file(filec, 1); myfw(fdx, blss_data, blss.num); fclose(fdx); myfree(&filec); break; } case OUT_MDS: { filec = change_ext(fileo, ".mds"); fdx = open_file(filec, 1); myfw(fdx, blss_data, blss.num); fclose(fdx); myfree(&filec); break; } case OUT_CCD: { p = blss_data + 8; getxx(blss_data, &tmp, 32, 0); filec = change_ext(fileo, ".ccd"); fdx = open_file(filec, 1); myfw(fdx, p, tmp); fclose(fdx); myfree(&filec); p += tmp; getxx(blss_data + 4, &tmp, 32, 0); filec = change_ext(fileo, ".sub"); fdx = open_file(filec, 1); myfw(fdx, p, tmp); fclose(fdx); myfree(&filec); break; } case OUT_NRG: { break; } default: break; // handled previously } } printf("- start unpacking:\n"); for(i = 0; i < blhr.num; i++) { l2n_blhr_data(&blhr_data[i]); printf(" %03d%%\r", (i * 100) / blhr.num); #ifdef VERBOSE printf("\n" "offset %08x%08x\n" "input size %08x\n" "output sector %08x\n" "sectors %08x\n" "type %08x\n", PRINTF64(blhr_data[i].offset), blhr_data[i].zsize, blhr_data[i].sector, blhr_data[i].size, blhr_data[i].type); #endif myalloc(&in, blhr_data[i].zsize, &insz); if(blhr_data[i].zsize) { if(fseek(fdi, blhr_data[i].offset, SEEK_SET)) std_err(); myfr(fdi, in, blhr_data[i].zsize); magiciso_is_shit_dec(shit_key_data, in, blhr_data[i].zsize); uif_crypt(des_ctx, in, blhr_data[i].zsize); } if(bbis.lastdiff && ((blhr_data[i].sector + blhr_data[i].size) >= bbis.sectors)) { lastdiff = bbis.sectorsz - bbis.lastdiff; } blhr_data[i].size *= bbis.sectorsz; myalloc(&out, blhr_data[i].size, &outsz); switch(blhr_data[i].type) { case 1: { // non compressed if(blhr_data[i].zsize > blhr_data[i].size) { printf("\nError: input size is bigger than output\n"); myexit(); } memcpy(out, in, blhr_data[i].zsize); if(blhr_data[i].zsize < blhr_data[i].size) { memset(out + blhr_data[i].zsize, 0, blhr_data[i].size - blhr_data[i].zsize); // needed? } break; } case 3: { // multi byte memset(out, 0, blhr_data[i].size); break; } case 5: { // compressed unlzma(lzma, in, blhr_data[i].zsize, out, blhr_data[i].size); unzip(z, in, blhr_data[i].zsize, out, blhr_data[i].size); break; } default: { printf("\nError: unknown type (%d)\n", blhr_data[i].type); myexit(); } } if(fseek(fdo, (u64)blhr_data[i].sector * (u64)bbis.sectorsz, SEEK_SET)) std_err(); if(lastdiff) { blhr_data[i].size -= lastdiff; // remove the superflous bytes at the end lastdiff = 0; } myfw(fdo, out, blhr_data[i].size); tot += blhr_data[i].size; } printf(" 100%%\n" "- 0x%08x%08x bytes written\n", PRINTF64(tot)); fclose(fdi); fclose(fdo); if(z) { inflateEnd(z); myfree((void *)&z); } if(lzma) { LzmaDec_Free(lzma, &g_Alloc); myfree((void *)&lzma); } magiciso_is_shit_free(shit_key_blhr); magiciso_is_shit_free(shit_key_data); if(des_ctx) myfree((void *)&des_ctx); if(outtype == OUT_NRG) { printf( "\n" " Please keep in mind that MagicISO creates INVALID NRG files which not only\n" " are unreadable by the various burners/mounters/converters for this type of\n" " image but also by the same Nero which owns the original NRG format, so if the\n" " output NRG file doesn't work is enough \"normal\".\n" "\n"); #ifdef NRGFIX printf( " This is the reason why this tool will create an additional CUE file which can\n" " be used in case the NRG one doesn't work. If you are trying to mount the CUE\n" " file but it gives errors or you see no data try to enable all the emulation\n" " options of your mounting program and it will work perfectly.\n" "\n"); nrg_truncate(fileo, bbis.sectorsz * 2); // max 1 sector plus another one if NER5 is not in the last one #endif } printf("- finished\n"); myexit(); return(0); } #ifdef WIN32 char *get_file(void) { OPENFILENAME ofn; static char filename[4096]; static const char filter[] = "UIF file\0" "*.uif\0" "(*.*)\0" "*.*\0" "\0" "\0"; filename[0] = 0; memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename); ofn.lpstrTitle = "Select the input UIF file to convert"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY; printf("- %s\n", ofn.lpstrTitle); if(!GetOpenFileName(&ofn)) exit(1); return(filename); } char *put_file(char *suggested) { OPENFILENAME ofn; char *p; static char filename[4096 + 10]; static const char filter[] = "image file\0" "*.iso;*.cue;*.bin;*.mds;*.mdf;*.ccd;*.img;*.sub;*.nrg\0" "(*.*)\0" "*.*\0" "\0" "\0"; if(!suggested) { filename[0] = 0; } else { p = strrchr(suggested, '.'); if(!p) p = suggested + strlen(suggested); if((p - suggested) >= 4096) p = suggested + 4096 - 1; memcpy(filename, suggested, p - suggested); filename[p - suggested] = 0; } memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename); ofn.lpstrTitle = "Choose the name of the output file to create (the extension is automatic)"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY; printf("- %s\n", ofn.lpstrTitle); if(!GetSaveFileName(&ofn)) exit(1); return(filename); } #endif void myfree(u8 **mem) { if(*mem) { free(*mem); *mem = NULL; } } u8 *path2fname(u8 *path) { u8 *p; p = strrchr(path, '\\'); if(!p) p = strrchr(path, '/'); if(p) return(p + 1); return(path); } u8 *frames2time(u64 num) { int mm, ss, ff; static u8 ret_time[32]; num /= 2352; // default sector size ff = num % 75; ss = (num / 75) % 60; mm = (num / 75) / 60; sprintf(ret_time, "%02d:%02d:%02d", mm, ss, ff); return(ret_time); } void nrg2cue(FILE *fd, u64 nrgoff, u8 *fileo) { nrg_chunk_t chunk; FILE *fdcue = NULL, *fdcdt = NULL; u64 index0, index1, index2; u32 sectsz, mode; int i, numsz, track, firstindex = 1; u8 *filec = NULL, *filecdt = NULL, *buff = NULL, *p, *l; if(fseek(fd, nrgoff, SEEK_SET)) { printf("- Alert: wrong NRG header offset\n"); return; } printf("- generate a new CUE file derived from the NRG one\n"); filec = change_ext(fileo, "_nrg.cue"); fdcue = open_file(filec, 1); fprintf(fdcue, "FILE \"%s\" BINARY\r\n", path2fname(fileo)); track = 1; for(;;) { // get tracks and do more things myfr(fd, &chunk, sizeof(chunk)); b2n_32(&chunk.size); if(!memcmp(chunk.id, "NER5", 4) || !memcmp(chunk.id, "NERO", 4)) break; if(!memcmp(chunk.id, "DAOX", 4) || !memcmp(chunk.id, "DAOI", 4)) { if(chunk.size >= 22) { buff = malloc(chunk.size); if(!buff) std_err(); myfr(fd, buff, chunk.size); numsz = (!memcmp(chunk.id, "DAOX", 4)) ? 8 : 4; p = buff + 22; l = buff + chunk.size - (4 + 4 + (numsz * 3)); for(i = 0; p <= l; i++) { p += 10; sectsz = *(u32 *)p; p += 4; b2n_32(§sz); mode = p[0]; p += 4; p += getxx(p, &index0, numsz << 3, 1); p += getxx(p, &index1, numsz << 3, 1); p += getxx(p, &index2, numsz << 3, 1); #ifdef VERBOSE printf(" %08x %02x %08x%08x %08x%08x %08x%08x\n", sectsz, mode, PRINTF64(index0), PRINTF64(index1), PRINTF64(index2)); #endif switch(mode) { // case 2: yes, this is data mode 2 BUT the CUE will give an error if you use this mode! case 3: fprintf(fdcue, " TRACK %02d MODE2/%u\r\n", track, sectsz); break; case 7: fprintf(fdcue, " TRACK %02d AUDIO\r\n", track); break; case 0: default:fprintf(fdcue, " TRACK %02d MODE1/%u\r\n", track, sectsz); break; } if(firstindex) { fprintf(fdcue, " INDEX 00 00:00:00\r\n"); firstindex = 0; } else if(index1 > index0) { fprintf(fdcue, " INDEX 00 %s\r\n", frames2time(index0)); } fprintf(fdcue, " INDEX 01 %s\r\n", frames2time(index1)); track++; } myfree(&buff); continue; } } if(!memcmp(chunk.id, "ETN2", 4) || !memcmp(chunk.id, "ETNF", 4)) { if(chunk.size >= 22) { buff = malloc(chunk.size); if(!buff) std_err(); myfr(fd, buff, chunk.size); numsz = (!memcmp(chunk.id, "ETN2", 4)) ? 8 : 4; sectsz = 2352; // right??? p = buff; l = buff + chunk.size - ((numsz * 2) + 4 + 4 + 4); for(i = 0; p <= l; i++) { p += getxx(p, &index1, numsz << 3, 1); p += getxx(p, &index2, numsz << 3, 1); mode = p[0]; p += 4; p += 4 + 4; #ifdef VERBOSE printf(" %02x %08x%08x %08x%08x\n", mode, PRINTF64(index1), PRINTF64(index2)); #endif switch(mode) { case 3: fprintf(fdcue, " TRACK %02d MODE2/%u\r\n", track, sectsz); break; case 7: fprintf(fdcue, " TRACK %02d AUDIO\r\n", track); break; case 0: default:fprintf(fdcue, " TRACK %02d MODE1/%u\r\n", track, sectsz); break; } if(!i) fprintf(fdcue, " INDEX 00 00:00:00\r\n"); fprintf(fdcue, " INDEX 01 %s\r\n", frames2time(index1)); track++; } myfree(&buff); continue; } } if(!memcmp(chunk.id, "CDTX", 4)) { buff = malloc(chunk.size); if(!buff) std_err(); myfr(fd, buff, chunk.size); filecdt = change_ext(fileo, ".cdt"); fdcdt = open_file(filecdt, 1); myfw(fdcdt, buff, chunk.size); fclose(fdcdt); fprintf(fdcue, "CDTEXTFILE \"%s\"\r\n", path2fname(filecdt)); myfree(&buff); continue; } if(fseek(fd, chunk.size, SEEK_CUR)) break; } fclose(fdcue); } void magiciso_is_invalid(FILE *fd, u64 nrgoff, u8 *fileo) { nrg_chunk_t chunk; u64 index2; int numsz, track; u8 tracks, // can't be more than 8bit *buff = NULL; if(fseek(fd, nrgoff, SEEK_SET)) { printf("- Alert: wrong NRG header offset\n"); return; } track = 1; tracks = 1; for(;;) { // get tracks and do more things myfr(fd, &chunk, sizeof(chunk)); b2n_32(&chunk.size); if(!memcmp(chunk.id, "NER5", 4) || !memcmp(chunk.id, "NERO", 4)) break; if(!memcmp(chunk.id, "DAOX", 4) || !memcmp(chunk.id, "DAOI", 4)) { if(chunk.size >= 22) { buff = malloc(chunk.size); if(!buff) std_err(); myfr(fd, buff, chunk.size); tracks = (buff[21] - buff[20]) + 1; numsz = (!memcmp(chunk.id, "DAOX", 4)) ? 8 : 4; getxx(buff + chunk.size - numsz, &index2, numsz << 3, 1); if(index2 > nrgoff) { putxx(buff + chunk.size - numsz, nrgoff, numsz << 3, 1); printf("- correcting last DAO index2\n"); fseek(fd, -numsz, SEEK_CUR); myfw(fd, buff + chunk.size - numsz, numsz); fflush(fd); // you can't imagine how much required is this fflush... } myfree(&buff); continue; // skip the fseek chunk.size stuff made at each cycle } } if(!memcmp(chunk.id, "SINF", 4)) { // usually located after DAO if(chunk.size >= 4) { if(fseek(fd, 3, SEEK_CUR)) break; printf("- correcting SINF to %u tracks\n", tracks); myfw(fd, &tracks, 1); fflush(fd); // you can't imagine how much required is this fflush... fseek(fd, -4, SEEK_CUR); // restore } } if(fseek(fd, chunk.size, SEEK_CUR)) break; } } void nrg_truncate(u8 *fileo, int secsz) { FILE *fd = NULL; u64 truncsize, realsize, nrgoff; int truncseek; u8 *buff = NULL, *p; fd = fopen(fileo, "r+b"); if(!fd) return; fflush(fd); fseek(fd, 0, SEEK_END); realsize = ftell(fd); if(!fseek(fd, -secsz, SEEK_END)) { buff = malloc(secsz); if(!buff) std_err(); myfr(fd, buff, secsz); for(p = buff + secsz - 12; p >= buff; p--) { if(!memcmp(p, "NER5", 4)) { nrgoff = *(u64 *)(p + 4); p += 12; break; } if(!memcmp(p, "NERO", 4)) { nrgoff = *(u32 *)(p + 4); p += 8; break; } } if(p >= buff) { truncseek = -(secsz - (p - buff)); b2n_64(&nrgoff); magiciso_is_invalid(fd, nrgoff, fileo); nrg2cue(fd, nrgoff, fileo); fseek(fd, truncseek, SEEK_END); fflush(fd); truncsize = ftell(fd); if(realsize != truncsize) { printf("- found NRG end of file at offset 0x%08x%08x\n", PRINTF64(truncsize)); ftruncate(fileno(fd), truncsize); // trick to spawn errors or warnings if there is no large file support fflush(fd); fclose(fd); fd = fopen(fileo, "rb"); // verify if the truncation was correct if(!fd) return; fseek(fd, 0, SEEK_END); realsize = ftell(fd); if(realsize < truncsize) { printf("\n" "Error: the truncated file is smaller than how much I requested\n" " is possible that ftruncate() doesn't support large files\n" " Please contact me reporting also the sizeo of the UIF and your platform\n"); } else if(realsize != truncsize) { printf("- Alert: seems that the file has not been truncated to the correct NRG size\n"); } } } myfree(&buff); } fclose(fd); } u8 *blhr_unzip(FILE *fd, z_stream *z, CLzmaDec *lzma, des_context *des_ctx, u32 zsize, u32 unzsize, int compressed) { static int insz = 0; static u8 *in = NULL; u8 *data; if(compressed) { myalloc(&in, zsize, &insz); myfr(fd, in, zsize); magiciso_is_shit_dec(shit_key_blhr, in, zsize); if(des_ctx) uif_crypt(des_ctx, in, zsize); data = malloc(unzsize); if(!data) std_err(); unlzma(lzma, in, zsize, (u8 *)data, unzsize); unzip(z, in, zsize, (u8 *)data, unzsize); } else { data = malloc(unzsize); if(!data) std_err(); myfr(fd, data, unzsize); magiciso_is_shit_dec(shit_key_blhr, data, unzsize); } return(data); } u8 *change_ext(u8 *fname, u8 *ext) { u8 *p; p = malloc(strlen(fname) + strlen(ext) + 1); if(!p) std_err(); strcpy(p, fname); fname = p; p = strrchr(fname, '.'); if(!p || (p && (strlen(p) != 4))) p = fname + strlen(fname); strcpy(p, ext); return(fname); } FILE *open_file(u8 *fname, int write) { FILE *fd = NULL; u8 ans[16]; if(write) { printf("- create %s\n", fname); fd = fopen(fname, "rb"); if(fd) { fclose(fd); printf("- the output file already exists, do you want to overwrite it (y/N)? "); fgetz(ans, sizeof(ans), stdin); if((ans[0] != 'y') && (ans[0] != 'Y')) myexit(); } fd = fopen(fname, "wb"); if(!fd) std_err(); } else { printf("- open %s\n", fname); fd = fopen(fname, "rb"); if(!fd) std_err(); } return(fd); } int blms2cue(FILE *fd, u8 *fname, u8 *blms, int blms_len) { u32 bin, cue, type; int track, mode, tot; u8 mm, ss, ff, *p; if(blms_len < 0x40) return(-1); bin = *(u32 *)(blms + 0x04); l2n_32(&bin); if(bin > blms_len) return(-1); cue = *(u32 *)(blms + 0x10); l2n_32(&cue); if(cue > blms_len) return(-1); p = blms + 0x40; if(bin) { p = blms + bin; printf("- BIN name stored in the UIF file: %s\n", p); p += strlen(p) + 1; } if(cue) { p = blms + cue; printf("- CUE name stored in the UIF file: %s\n", p); p += strlen(p) + 1; } fprintf(fd, "FILE \"%s\" BINARY\r\n", fname); for(tot = 0; (p - blms) < blms_len; p += 68) { if(p[3] & 0xa0) continue; track = p[3]; mode = p[11]; mm = p[8]; ss = p[9] - 2; // these are the 2 seconds located at the beginning of the NRG file ff = p[10]; type = *(u32 *)(p + 24); l2n_32(&type); switch(p[1]) { case 0x10: case 0x12: { fprintf(fd, " TRACK %02d AUDIO\r\n", track); } break; case 0x14: default: { fprintf(fd, " TRACK %02d MODE%d/%d\r\n", track, mode, type); } break; } fprintf(fd, " INDEX %02d %02d:%02d:%02d\r\n", 1, mm, ss, ff); tot++; } return(tot); } void uif_crypt_key(des_context **des_ctx, u8 *key, u8 *pwd) { i64 *k, a, b; int i; if(!des_ctx) return; if(!*des_ctx) { *des_ctx = malloc(sizeof(des_context)); if(!*des_ctx) std_err(); } strncpy(key, pwd, 32); k = (i64 *)key; printf("- set DES encryption key: %.32s\n", key); for(i = 1; i < 4; i++) { if(!endian) { // this solution is required for little/big endian compatibility and speed k[0] += k[i]; continue; } a = k[0]; b = k[i]; l2n_64(&a); l2n_64(&b); a += b; l2n_64(&a); k[0] = a; } printf("- DES password: %02x %02x %02x %02x %02x %02x %02x %02x\n", key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]); } void uif_crypt(des_context *des_ctx, u8 *data, int size) { u8 *p, *l; if(!des_ctx) return; l = data + size - (size & 7); for(p = data; p < l; p += 8) { des_crypt_ecb(des_ctx, p, p); } } u8 *show_hash(u8 *hash) { int i; static u8 vis[33]; static const char hex[16] = "0123456789abcdef"; u8 *p; p = vis; for(i = 0; i < 16; i++) { *p++ = hex[hash[i] >> 4]; *p++ = hex[hash[i] & 15]; } *p = 0; return(vis); } void myalloc(u8 **data, unsigned wantsize, unsigned *currsize) { if(wantsize <= *currsize) return; *data = realloc(*data, wantsize); if(!*data) std_err(); *currsize = wantsize; } void myfr(FILE *fd, void *data, unsigned size) { if(fread(data, 1, size, fd) == size) return; printf("\nError: incomplete input file, can't read %u bytes\n", size); myexit(); } void myfw(FILE *fd, void *data, unsigned size) { if(fwrite(data, 1, size, fd) == size) return; printf("\nError: problems during the writing of the output file\n"); myexit(); } u32 unlzma(CLzmaDec *lzma, u8 *in, u32 insz, u8 *out, u32 outsz) { ELzmaStatus status; SizeT inlen, outlen; if(!lzma) return(0); if(insz < 14) { printf("\nError: the input lzma block is too short (%u)\n", insz); myexit(); } LzmaDec_Allocate(lzma, in + 1, LZMA_PROPS_SIZE, &g_Alloc); LzmaDec_Init(lzma); in += 14; inlen = insz - 14; outlen = outsz; if(LzmaDec_DecodeToBuf(lzma, out, &outlen, in, &inlen, LZMA_FINISH_END, &status) /* if(LzmaDecode(out, &outlen, in + 14, &inlen, in + 1, LZMA_PROPS_SIZE, LZMA_FINISH_END, &status, &g_Alloc) */ != SZ_OK) { printf("\nError: the compressed LZMA input is wrong or incomplete (%d)\n", status); myexit(); } return(outlen); } u32 unzip(z_stream *z, u8 *in, u32 insz, u8 *out, u32 outsz) { if(!z) return(0); inflateReset(z); z->next_in = in; z->avail_in = insz; z->next_out = out; z->avail_out = outsz; if(inflate(z, Z_SYNC_FLUSH) != Z_STREAM_END) { printf("\nError: the compressed input is wrong or incomplete\n"); myexit(); } return(z->total_out); } void l2n_blhr(blhr_t *p) { if(!endian) return; l2n_32(&p->sign); l2n_32(&p->size); l2n_32(&p->compressed); l2n_32(&p->num); } void l2n_blhr_data(blhr_data_t *p) { if(!endian) return; l2n_64(&p->offset); l2n_32(&p->zsize); l2n_32(&p->sector); l2n_32(&p->size); l2n_32(&p->type); } void l2n_bbis(bbis_t *p) { if(!endian) return; l2n_32(&p->sign); l2n_32(&p->bbis_size); l2n_16(&p->ver); l2n_16(&p->image_type); l2n_16(&p->unknown1); l2n_16(&p->padding); l2n_32(&p->sectors); l2n_32(&p->sectorsz); l2n_32(&p->lastdiff); l2n_64(&p->blhr); l2n_32(&p->blhrbbissz); l2n_32(&p->unknown4); } void l2n_16(u16 *num) { u16 tmp; if(!endian) return; tmp = *num; *num = ((tmp & 0xff00) >> 8) | ((tmp & 0x00ff) << 8); } void l2n_32(u32 *num) { u32 tmp; if(!endian) return; tmp = *num; *num = ((tmp & 0xff000000) >> 24) | ((tmp & 0x00ff0000) >> 8) | ((tmp & 0x0000ff00) << 8) | ((tmp & 0x000000ff) << 24); } void l2n_64(u64 *num) { u64 tmp; if(!endian) return; tmp = *num; *num = (u64)((u64)(tmp & (u64)0xff00000000000000ULL) >> (u64)56) | (u64)((u64)(tmp & (u64)0x00ff000000000000ULL) >> (u64)40) | (u64)((u64)(tmp & (u64)0x0000ff0000000000ULL) >> (u64)24) | (u64)((u64)(tmp & (u64)0x000000ff00000000ULL) >> (u64)8) | (u64)((u64)(tmp & (u64)0x00000000ff000000ULL) << (u64)8) | (u64)((u64)(tmp & (u64)0x0000000000ff0000ULL) << (u64)24) | (u64)((u64)(tmp & (u64)0x000000000000ff00ULL) << (u64)40) | (u64)((u64)(tmp & (u64)0x00000000000000ffULL) << (u64)56); } void b2n_16(u16 *num) { u16 tmp; if(endian) return; tmp = *num; *num = ((tmp & 0xff00) >> 8) | ((tmp & 0x00ff) << 8); } void b2n_32(u32 *num) { u32 tmp; if(endian) return; tmp = *num; *num = ((tmp & 0xff000000) >> 24) | ((tmp & 0x00ff0000) >> 8) | ((tmp & 0x0000ff00) << 8) | ((tmp & 0x000000ff) << 24); } void b2n_64(u64 *num) { u64 tmp; if(endian) return; tmp = *num; *num = (u64)((u64)(tmp & (u64)0xff00000000000000ULL) >> (u64)56) | (u64)((u64)(tmp & (u64)0x00ff000000000000ULL) >> (u64)40) | (u64)((u64)(tmp & (u64)0x0000ff0000000000ULL) >> (u64)24) | (u64)((u64)(tmp & (u64)0x000000ff00000000ULL) >> (u64)8) | (u64)((u64)(tmp & (u64)0x00000000ff000000ULL) << (u64)8) | (u64)((u64)(tmp & (u64)0x0000000000ff0000ULL) << (u64)24) | (u64)((u64)(tmp & (u64)0x000000000000ff00ULL) << (u64)40) | (u64)((u64)(tmp & (u64)0x00000000000000ffULL) << (u64)56); } int getxx(u8 *data, u64 *ret, int bits, int intnet) { u64 num; int i, bytes; num = 0; bytes = bits >> 3; for(i = 0; i < bytes; i++) { if(!intnet) { // intel/little endian num |= (data[i] << (i << 3)); } else { // network/big endian num |= (data[i] << ((bytes - 1 - i) << 3)); } } *ret = num; return(bytes); } int putxx(u8 *data, u64 num, int bits, int intnet) { int i, bytes; bytes = bits >> 3; for(i = 0; i < bytes; i++) { if(!intnet) { data[i] = (num >> (i << 3)) & 0xff; } else { data[i] = (num >> ((bytes - 1 - i) << 3)) & 0xff; } } return(bytes); } void std_err(void) { perror("\nError"); myexit(); } int fgetz(u8 *data, int size, FILE *fd) { u8 *p; fflush(fd); if(!fgets(data, size, fd)) { data[0] = 0; return(0); } for(p = data; *p && (*p != '\n') && (*p != '\r'); p++); *p = 0; return(p - data); } void myexit(void) { #ifdef WIN32 u8 ans[8]; if(GetWindowLong(mywnd, GWL_WNDPROC)) { printf("\nPress RETURN to quit"); fgetz(ans, sizeof(ans), stdin); } #endif exit(1); } uif2iso-0.1.7a/src/des.c0000644000175100017510000005452310752571014013723 0ustar margamarga/* * FIPS-46-3 compliant Triple-DES implementation * * Copyright (C) 2006-2007 Christophe Devine * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License, version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ /* * DES, on which TDES is based, was originally designed by Hans Feistel * at IBM in 1974, and was adopted as a standard by NIST (formerly NBS). * * http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf */ //#include "xyssl/config.h" //#if defined(XYSSL_DES_C) #include "des.h" #include /* * 32-bit integer manipulation macros (big endian) */ #ifndef GET_ULONG_BE #define GET_ULONG_BE(n,b,i) \ { \ (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ | ( (unsigned long) (b)[(i) + 1] << 16 ) \ | ( (unsigned long) (b)[(i) + 2] << 8 ) \ | ( (unsigned long) (b)[(i) + 3] ); \ } #endif #ifndef PUT_ULONG_BE #define PUT_ULONG_BE(n,b,i) \ { \ (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ (b)[(i) + 3] = (unsigned char) ( (n) ); \ } #endif /* * Expanded DES S-boxes */ static const unsigned long SB1[64] = { 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000, 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404, 0x00010004, 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000, 0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400, 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404, 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004, 0x00000404, 0x00010404, 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000, 0x01010004 }; static const unsigned long SB2[64] = { 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020, 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000, 0x00100020, 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000, 0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020, 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000, 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020, 0x80008020, 0x80000020, 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020, 0x00108000 }; static const unsigned long SB3[64] = { 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200, 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208, 0x08000208, 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200, 0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208, 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008, 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008, 0x00020208, 0x00020200, 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008, 0x00020200 }; static const unsigned long SB4[64] = { 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001, 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080, 0x00800081, 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080, 0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081, 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001, 0x00002001, 0x00802080, 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000, 0x00802080 }; static const unsigned long SB5[64] = { 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000, 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100, 0x42080000, 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000, 0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000, 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000, 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000, 0x00000000, 0x40080000, 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100, 0x40000100 }; static const unsigned long SB6[64] = { 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000, 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010, 0x20400010, 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000, 0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000, 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000, 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010, 0x00004000, 0x20400000, 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010, 0x20004010 }; static const unsigned long SB7[64] = { 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800, 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002, 0x04200000, 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000, 0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800, 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800, 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800, 0x00000000, 0x00000002, 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800, 0x00200002 }; static const unsigned long SB8[64] = { 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000, 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000, 0x00001040, 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040, 0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040, 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000, 0x10041000 }; /* * PC1: left and right halves bit-swap */ static const unsigned long LHs[16] = { 0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101, 0x01000000, 0x01000001, 0x01000100, 0x01000101, 0x01010000, 0x01010001, 0x01010100, 0x01010101 }; static const unsigned long RHs[16] = { 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, 0x00010100, 0x01010100, 0x00000001, 0x01000001, 0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101, 0x01010101, }; /* * Initial Permutation macro */ #define DES_IP(X,Y) \ { \ T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \ T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \ T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \ T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \ Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \ T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \ X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \ } /* * Final Permutation macro */ #define DES_FP(X,Y) \ { \ X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \ T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \ Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \ T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \ T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \ T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \ T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \ } /* * DES round macro */ #define DES_ROUND(X,Y) \ { \ T = *SK++ ^ X; \ Y ^= SB8[ (T ) & 0x3F ] ^ \ SB6[ (T >> 8) & 0x3F ] ^ \ SB4[ (T >> 16) & 0x3F ] ^ \ SB2[ (T >> 24) & 0x3F ]; \ \ T = *SK++ ^ ((X << 28) | (X >> 4)); \ Y ^= SB7[ (T ) & 0x3F ] ^ \ SB5[ (T >> 8) & 0x3F ] ^ \ SB3[ (T >> 16) & 0x3F ] ^ \ SB1[ (T >> 24) & 0x3F ]; \ } #define SWAP(a,b) { unsigned long t = a; a = b; b = t; t = 0; } static void des_setkey( unsigned long SK[32], unsigned char key[8] ) { int i; unsigned long X, Y, T; GET_ULONG_BE( X, key, 0 ); GET_ULONG_BE( Y, key, 4 ); /* * Permuted Choice 1 */ T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4); T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T ); X = (LHs[ (X ) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2) | (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ] ) | (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6) | (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4); Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2) | (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ] ) | (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6) | (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4); X &= 0x0FFFFFFF; Y &= 0x0FFFFFFF; /* * calculate subkeys */ for( i = 0; i < 16; i++ ) { if( i < 2 || i == 8 || i == 15 ) { X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF; Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF; } else { X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF; Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF; } *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000) | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000) | ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000) | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000) | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000) | ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000) | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400) | ((Y >> 14) & 0x00000200) | ((Y ) & 0x00000100) | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010) | ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004) | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001); *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000) | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000) | ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000) | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000) | ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000) | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000) | ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000) | ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400) | ((Y ) & 0x00000200) | ((Y << 7) & 0x00000100) | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011) | ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002); } } /* * DES key schedule (56-bit, encryption) */ void des_setkey_enc( des_context *ctx, unsigned char key[8] ) { des_setkey( ctx->sk, key ); } /* * DES key schedule (56-bit, decryption) */ void des_setkey_dec( des_context *ctx, unsigned char key[8] ) { int i; des_setkey( ctx->sk, key ); for( i = 0; i < 16; i += 2 ) { SWAP( ctx->sk[i ], ctx->sk[30 - i] ); SWAP( ctx->sk[i + 1], ctx->sk[31 - i] ); } } static void des3_set2key( unsigned long esk[96], unsigned long dsk[96], unsigned char key[16] ) { int i; des_setkey( esk, key ); des_setkey( dsk + 32, key + 8 ); for( i = 0; i < 32; i += 2 ) { dsk[i ] = esk[30 - i]; dsk[i + 1] = esk[31 - i]; esk[i + 32] = dsk[62 - i]; esk[i + 33] = dsk[63 - i]; esk[i + 64] = esk[i ]; esk[i + 65] = esk[i + 1]; dsk[i + 64] = dsk[i ]; dsk[i + 65] = dsk[i + 1]; } } /* * Triple-DES key schedule (112-bit, encryption) */ void des3_set2key_enc( des3_context *ctx, unsigned char key[16] ) { unsigned long sk[96]; des3_set2key( ctx->sk, sk, key ); memset( sk, 0, sizeof( sk ) ); } /* * Triple-DES key schedule (112-bit, decryption) */ void des3_set2key_dec( des3_context *ctx, unsigned char key[16] ) { unsigned long sk[96]; des3_set2key( sk, ctx->sk, key ); memset( sk, 0, sizeof( sk ) ); } static void des3_set3key( unsigned long esk[96], unsigned long dsk[96], unsigned char key[24] ) { int i; des_setkey( esk, key ); des_setkey( dsk + 32, key + 8 ); des_setkey( esk + 64, key + 16 ); for( i = 0; i < 32; i += 2 ) { dsk[i ] = esk[94 - i]; dsk[i + 1] = esk[95 - i]; esk[i + 32] = dsk[62 - i]; esk[i + 33] = dsk[63 - i]; dsk[i + 64] = esk[30 - i]; dsk[i + 65] = esk[31 - i]; } } /* * Triple-DES key schedule (168-bit, encryption) */ void des3_set3key_enc( des3_context *ctx, unsigned char key[24] ) { unsigned long sk[96]; des3_set3key( ctx->sk, sk, key ); memset( sk, 0, sizeof( sk ) ); } /* * Triple-DES key schedule (168-bit, decryption) */ void des3_set3key_dec( des3_context *ctx, unsigned char key[24] ) { unsigned long sk[96]; des3_set3key( sk, ctx->sk, key ); memset( sk, 0, sizeof( sk ) ); } /* * DES-ECB block encryption/decryption */ void des_crypt_ecb( des_context *ctx, unsigned char input[8], unsigned char output[8] ) { int i; unsigned long X, Y, T, *SK; SK = ctx->sk; GET_ULONG_BE( X, input, 0 ); GET_ULONG_BE( Y, input, 4 ); DES_IP( X, Y ); for( i = 0; i < 8; i++ ) { DES_ROUND( Y, X ); DES_ROUND( X, Y ); } DES_FP( Y, X ); PUT_ULONG_BE( Y, output, 0 ); PUT_ULONG_BE( X, output, 4 ); } /* * DES-CBC buffer encryption/decryption */ void des_crypt_cbc( des_context *ctx, int mode, int length, unsigned char iv[8], unsigned char *input, unsigned char *output ) { int i; unsigned char temp[8]; if( mode == DES_ENCRYPT ) { while( length > 0 ) { for( i = 0; i < 8; i++ ) output[i] = (unsigned char)( input[i] ^ iv[i] ); des_crypt_ecb( ctx, output, output ); memcpy( iv, output, 8 ); input += 8; output += 8; length -= 8; } } else /* DES_DECRYPT */ { while( length > 0 ) { memcpy( temp, input, 8 ); des_crypt_ecb( ctx, input, output ); for( i = 0; i < 8; i++ ) output[i] = (unsigned char)( output[i] ^ iv[i] ); memcpy( iv, temp, 8 ); input += 8; output += 8; length -= 8; } } } /* * 3DES-ECB block encryption/decryption */ void des3_crypt_ecb( des3_context *ctx, unsigned char input[8], unsigned char output[8] ) { int i; unsigned long X, Y, T, *SK; SK = ctx->sk; GET_ULONG_BE( X, input, 0 ); GET_ULONG_BE( Y, input, 4 ); DES_IP( X, Y ); for( i = 0; i < 8; i++ ) { DES_ROUND( Y, X ); DES_ROUND( X, Y ); } for( i = 0; i < 8; i++ ) { DES_ROUND( X, Y ); DES_ROUND( Y, X ); } for( i = 0; i < 8; i++ ) { DES_ROUND( Y, X ); DES_ROUND( X, Y ); } DES_FP( Y, X ); PUT_ULONG_BE( Y, output, 0 ); PUT_ULONG_BE( X, output, 4 ); } /* * 3DES-CBC buffer encryption/decryption */ void des3_crypt_cbc( des3_context *ctx, int mode, int length, unsigned char iv[8], unsigned char *input, unsigned char *output ) { int i; unsigned char temp[8]; if( mode == DES_ENCRYPT ) { while( length > 0 ) { for( i = 0; i < 8; i++ ) output[i] = (unsigned char)( input[i] ^ iv[i] ); des3_crypt_ecb( ctx, output, output ); memcpy( iv, output, 8 ); input += 8; output += 8; length -= 8; } } else /* DES_DECRYPT */ { while( length > 0 ) { memcpy( temp, input, 8 ); des3_crypt_ecb( ctx, input, output ); for( i = 0; i < 8; i++ ) output[i] = (unsigned char)( output[i] ^ iv[i] ); memcpy( iv, temp, 8 ); input += 8; output += 8; length -= 8; } } } #if defined(XYSSL_SELF_TEST) #include /* * DES/3DES test vectors (source: NIST, tripledes-vectors.zip) */ static const unsigned char DES3_keys[24] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23 }; static const unsigned char DES3_init[8] = { 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74 }; static const unsigned char DES3_enc_test[3][8] = { { 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B }, { 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 }, { 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 } }; static const unsigned char DES3_dec_test[3][8] = { { 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D }, { 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB }, { 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A } }; /* * Checkup routine */ int des_self_test( int verbose ) { int i, j, u, v; des_context ctx; des3_context ctx3; unsigned char buf[8]; for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " DES%c-ECB-%3d (%s): ", ( u == 0 ) ? ' ' : '3', 56 + u * 56, ( v == 0 ) ? "enc" : "dec" ); memcpy( buf, DES3_init, 8 ); switch( u ) { case 0: if( v == 0 ) des_setkey_enc( &ctx, (unsigned char *) DES3_keys ); if( v == 1 ) des_setkey_dec( &ctx, (unsigned char *) DES3_keys ); break; case 1: if( v == 0 ) des3_set2key_enc( &ctx3, (unsigned char *) DES3_keys ); if( v == 1 ) des3_set2key_dec( &ctx3, (unsigned char *) DES3_keys ); break; default: if( v == 0 ) des3_set3key_enc( &ctx3, (unsigned char *) DES3_keys ); if( v == 1 ) des3_set3key_dec( &ctx3, (unsigned char *) DES3_keys ); break; } for( j = 0; j < 10000; j++ ) { if( u == 0 ) des_crypt_ecb( &ctx, buf, buf ); else des3_crypt_ecb( &ctx3, buf, buf ); } if( ( v == 0 && memcmp( buf, DES3_enc_test[u], 8 ) != 0 ) || ( v == 1 && memcmp( buf, DES3_dec_test[u], 8 ) != 0 ) ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); return( 0 ); } #endif //#endif uif2iso-0.1.7a/src/LzmaDec.c0000644000175100017510000006556511070702650014473 0ustar margamarga/* LzmaDec.c -- LZMA Decoder 2008-04-29 Copyright (c) 1999-2008 Igor Pavlov Read LzmaDec.h for license options */ #include "LzmaDec.h" #include #define kNumTopBits 24 #define kTopValue ((UInt32)1 << kNumTopBits) #define kNumBitModelTotalBits 11 #define kBitModelTotal (1 << kNumBitModelTotalBits) #define kNumMoveBits 5 #define RC_INIT_SIZE 5 #define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } #define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) #define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); #define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); #define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \ { UPDATE_0(p); i = (i + i); A0; } else \ { UPDATE_1(p); i = (i + i) + 1; A1; } #define GET_BIT(p, i) GET_BIT2(p, i, ; , ;) #define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); } #define TREE_DECODE(probs, limit, i) \ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; } /* #define _LZMA_SIZE_OPT */ #ifdef _LZMA_SIZE_OPT #define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i) #else #define TREE_6_DECODE(probs, i) \ { i = 1; \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ i -= 0x40; } #endif #define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); } #define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) #define UPDATE_0_CHECK range = bound; #define UPDATE_1_CHECK range -= bound; code -= bound; #define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ { UPDATE_0_CHECK; i = (i + i); A0; } else \ { UPDATE_1_CHECK; i = (i + i) + 1; A1; } #define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;) #define TREE_DECODE_CHECK(probs, limit, i) \ { i = 1; do { GET_BIT_CHECK(probs + i, i) } while(i < limit); i -= limit; } #define kNumPosBitsMax 4 #define kNumPosStatesMax (1 << kNumPosBitsMax) #define kLenNumLowBits 3 #define kLenNumLowSymbols (1 << kLenNumLowBits) #define kLenNumMidBits 3 #define kLenNumMidSymbols (1 << kLenNumMidBits) #define kLenNumHighBits 8 #define kLenNumHighSymbols (1 << kLenNumHighBits) #define LenChoice 0 #define LenChoice2 (LenChoice + 1) #define LenLow (LenChoice2 + 1) #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) #define kNumLenProbs (LenHigh + kLenNumHighSymbols) #define kNumStates 12 #define kNumLitStates 7 #define kStartPosModelIndex 4 #define kEndPosModelIndex 14 #define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) #define kNumPosSlotBits 6 #define kNumLenToPosStates 4 #define kNumAlignBits 4 #define kAlignTableSize (1 << kNumAlignBits) #define kMatchMinLen 2 #define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols) #define IsMatch 0 #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) #define IsRepG0 (IsRep + kNumStates) #define IsRepG1 (IsRepG0 + kNumStates) #define IsRepG2 (IsRepG1 + kNumStates) #define IsRep0Long (IsRepG2 + kNumStates) #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) #define LenCoder (Align + kAlignTableSize) #define RepLenCoder (LenCoder + kNumLenProbs) #define Literal (RepLenCoder + kNumLenProbs) #define LZMA_BASE_SIZE 1846 #define LZMA_LIT_SIZE 768 #define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp))) #if Literal != LZMA_BASE_SIZE StopCompilingDueBUG #endif /* #define LZMA_STREAM_WAS_FINISHED_ID (-1) #define LZMA_SPEC_LEN_OFFSET (-3) */ Byte kLiteralNextStates[kNumStates * 2] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10 }; #define LZMA_DIC_MIN (1 << 12) /* First LZMA-symbol is always decoded. And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization Out: Result: 0 - OK 1 - Error p->remainLen: < kMatchSpecLenStart : normal remain = kMatchSpecLenStart : finished = kMatchSpecLenStart + 1 : Flush marker = kMatchSpecLenStart + 2 : State Init Marker */ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit) { CLzmaProb *probs = p->probs; unsigned state = p->state; UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1; unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; unsigned lc = p->prop.lc; Byte *dic = p->dic; SizeT dicBufSize = p->dicBufSize; SizeT dicPos = p->dicPos; UInt32 processedPos = p->processedPos; UInt32 checkDicSize = p->checkDicSize; unsigned len = 0; const Byte *buf = p->buf; UInt32 range = p->range; UInt32 code = p->code; do { CLzmaProb *prob; UInt32 bound; unsigned ttt; unsigned posState = processedPos & pbMask; prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; IF_BIT_0(prob) { unsigned symbol; UPDATE_0(prob); prob = probs + Literal; if (checkDicSize != 0 || processedPos != 0) prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc)))); if (state < kNumLitStates) { symbol = 1; do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100); } else { unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; unsigned offs = 0x100; symbol = 1; do { unsigned bit; CLzmaProb *probLit; matchByte <<= 1; bit = (matchByte & offs); probLit = prob + offs + bit + symbol; GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit) } while (symbol < 0x100); } dic[dicPos++] = (Byte)symbol; processedPos++; state = kLiteralNextStates[state]; /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */ continue; } else { UPDATE_1(prob); prob = probs + IsRep + state; IF_BIT_0(prob) { UPDATE_0(prob); state += kNumStates; prob = probs + LenCoder; } else { UPDATE_1(prob); if (checkDicSize == 0 && processedPos == 0) return SZ_ERROR_DATA; prob = probs + IsRepG0 + state; IF_BIT_0(prob) { UPDATE_0(prob); prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; IF_BIT_0(prob) { UPDATE_0(prob); dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; dicPos++; processedPos++; state = state < kNumLitStates ? 9 : 11; continue; } UPDATE_1(prob); } else { UInt32 distance; UPDATE_1(prob); prob = probs + IsRepG1 + state; IF_BIT_0(prob) { UPDATE_0(prob); distance = rep1; } else { UPDATE_1(prob); prob = probs + IsRepG2 + state; IF_BIT_0(prob) { UPDATE_0(prob); distance = rep2; } else { UPDATE_1(prob); distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } state = state < kNumLitStates ? 8 : 11; prob = probs + RepLenCoder; } { unsigned limit, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; limit = (1 << kLenNumLowBits); } else { UPDATE_1(probLen); probLen = prob + LenChoice2; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; limit = (1 << kLenNumMidBits); } else { UPDATE_1(probLen); probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; limit = (1 << kLenNumHighBits); } } TREE_DECODE(probLen, limit, len); len += offset; } if (state >= kNumStates) { UInt32 distance; prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); TREE_6_DECODE(prob, distance); if (distance >= kStartPosModelIndex) { unsigned posSlot = (unsigned)distance; int numDirectBits = (int)(((distance >> 1) - 1)); distance = (2 | (distance & 1)); if (posSlot < kEndPosModelIndex) { distance <<= numDirectBits; prob = probs + SpecPos + distance - posSlot - 1; { UInt32 mask = 1; unsigned i = 1; do { GET_BIT2(prob + i, i, ; , distance |= mask); mask <<= 1; } while(--numDirectBits != 0); } } else { numDirectBits -= kNumAlignBits; do { NORMALIZE range >>= 1; { UInt32 t; code -= range; t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */ distance = (distance << 1) + (t + 1); code += range & t; } /* distance <<= 1; if (code >= range) { code -= range; distance |= 1; } */ } while (--numDirectBits != 0); prob = probs + Align; distance <<= kNumAlignBits; { unsigned i = 1; GET_BIT2(prob + i, i, ; , distance |= 1); GET_BIT2(prob + i, i, ; , distance |= 2); GET_BIT2(prob + i, i, ; , distance |= 4); GET_BIT2(prob + i, i, ; , distance |= 8); } if (distance == (UInt32)0xFFFFFFFF) { len += kMatchSpecLenStart; state -= kNumStates; break; } } } rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance + 1; if (checkDicSize == 0) { if (distance >= processedPos) return SZ_ERROR_DATA; } else if (distance >= checkDicSize) return SZ_ERROR_DATA; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3; /* state = kLiteralNextStates[state]; */ } len += kMatchMinLen; { SizeT rem = limit - dicPos; unsigned curLen = ((rem < len) ? (unsigned)rem : len); SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0); processedPos += curLen; len -= curLen; if (pos + curLen <= dicBufSize) { Byte *dest = dic + dicPos; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; const Byte *lim = dest + curLen; dicPos += curLen; do *(dest) = (Byte)*(dest + src); while (++dest != lim); } else { do { dic[dicPos++] = dic[pos]; if (++pos == dicBufSize) pos = 0; } while (--curLen != 0); } } } } while (dicPos < limit && buf < bufLimit); NORMALIZE; p->buf = buf; p->range = range; p->code = code; p->remainLen = len; p->dicPos = dicPos; p->processedPos = processedPos; p->reps[0] = rep0; p->reps[1] = rep1; p->reps[2] = rep2; p->reps[3] = rep3; p->state = state; return SZ_OK; } static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) { if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) { Byte *dic = p->dic; SizeT dicPos = p->dicPos; SizeT dicBufSize = p->dicBufSize; unsigned len = p->remainLen; UInt32 rep0 = p->reps[0]; if (limit - dicPos < len) len = (unsigned)(limit - dicPos); if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len) p->checkDicSize = p->prop.dicSize; p->processedPos += len; p->remainLen -= len; while (len-- != 0) { dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; dicPos++; } p->dicPos = dicPos; } } /* LzmaDec_DecodeReal2 decodes LZMA-symbols and sets p->needFlush and p->needInit, if required. */ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) { do { SizeT limit2 = limit; if (p->checkDicSize == 0) { UInt32 rem = p->prop.dicSize - p->processedPos; if (limit - p->dicPos > rem) limit2 = p->dicPos + rem; } RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit)); if (p->processedPos >= p->prop.dicSize) p->checkDicSize = p->prop.dicSize; LzmaDec_WriteRem(p, limit); } while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart); if (p->remainLen > kMatchSpecLenStart) { p->remainLen = kMatchSpecLenStart; } return 0; } typedef enum { DUMMY_ERROR, /* unexpected end of input stream */ DUMMY_LIT, DUMMY_MATCH, DUMMY_REP } ELzmaDummy; static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) { UInt32 range = p->range; UInt32 code = p->code; const Byte *bufLimit = buf + inSize; CLzmaProb *probs = p->probs; unsigned state = p->state; ELzmaDummy res; { CLzmaProb *prob; UInt32 bound; unsigned ttt; unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK /* if (bufLimit - buf >= 7) return DUMMY_LIT; */ prob = probs + Literal; if (p->checkDicSize != 0 || p->processedPos != 0) prob += (LZMA_LIT_SIZE * ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) + (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc)))); if (state < kNumLitStates) { unsigned symbol = 1; do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100); } else { unsigned matchByte = p->dic[p->dicPos - p->reps[0] + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)]; unsigned offs = 0x100; unsigned symbol = 1; do { unsigned bit; CLzmaProb *probLit; matchByte <<= 1; bit = (matchByte & offs); probLit = prob + offs + bit + symbol; GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit) } while (symbol < 0x100); } res = DUMMY_LIT; } else { unsigned len; UPDATE_1_CHECK; prob = probs + IsRep + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; state = 0; prob = probs + LenCoder; res = DUMMY_MATCH; } else { UPDATE_1_CHECK; res = DUMMY_REP; prob = probs + IsRepG0 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; NORMALIZE_CHECK; return DUMMY_REP; } else { UPDATE_1_CHECK; } } else { UPDATE_1_CHECK; prob = probs + IsRepG1 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; } else { UPDATE_1_CHECK; prob = probs + IsRepG2 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; } else { UPDATE_1_CHECK; } } } state = kNumStates; prob = probs + RepLenCoder; } { unsigned limit, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0_CHECK(probLen) { UPDATE_0_CHECK; probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; limit = 1 << kLenNumLowBits; } else { UPDATE_1_CHECK; probLen = prob + LenChoice2; IF_BIT_0_CHECK(probLen) { UPDATE_0_CHECK; probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; limit = 1 << kLenNumMidBits; } else { UPDATE_1_CHECK; probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; limit = 1 << kLenNumHighBits; } } TREE_DECODE_CHECK(probLen, limit, len); len += offset; } if (state < 4) { unsigned posSlot; prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot); if (posSlot >= kStartPosModelIndex) { int numDirectBits = ((posSlot >> 1) - 1); /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */ if (posSlot < kEndPosModelIndex) { prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1; } else { numDirectBits -= kNumAlignBits; do { NORMALIZE_CHECK range >>= 1; code -= range & (((code - range) >> 31) - 1); /* if (code >= range) code -= range; */ } while (--numDirectBits != 0); prob = probs + Align; numDirectBits = kNumAlignBits; } { unsigned i = 1; do { GET_BIT_CHECK(prob + i, i); } while(--numDirectBits != 0); } } } } } NORMALIZE_CHECK; return res; } static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) { p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]); p->range = 0xFFFFFFFF; p->needFlush = 0; } void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) { p->needFlush = 1; p->remainLen = 0; p->tempBufSize = 0; if (initDic) { p->processedPos = 0; p->checkDicSize = 0; p->needInitState = 1; } if (initState) p->needInitState = 1; } void LzmaDec_Init(CLzmaDec *p) { p->dicPos = 0; LzmaDec_InitDicAndState(p, True, True); } static void LzmaDec_InitStateReal(CLzmaDec *p) { UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp)); UInt32 i; CLzmaProb *probs = p->probs; for (i = 0; i < numProbs; i++) probs[i] = kBitModelTotal >> 1; p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1; p->state = 0; p->needInitState = 0; } SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) { SizeT inSize = *srcLen; (*srcLen) = 0; LzmaDec_WriteRem(p, dicLimit); *status = LZMA_STATUS_NOT_SPECIFIED; while (p->remainLen != kMatchSpecLenStart) { int checkEndMarkNow; if (p->needFlush != 0) { for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--) p->tempBuf[p->tempBufSize++] = *src++; if (p->tempBufSize < RC_INIT_SIZE) { *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (p->tempBuf[0] != 0) return SZ_ERROR_DATA; LzmaDec_InitRc(p, p->tempBuf); p->tempBufSize = 0; } checkEndMarkNow = 0; if (p->dicPos >= dicLimit) { if (p->remainLen == 0 && p->code == 0) { *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK; return SZ_OK; } if (finishMode == LZMA_FINISH_ANY) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_OK; } if (p->remainLen != 0) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } checkEndMarkNow = 1; } if (p->needInitState) LzmaDec_InitStateReal(p); if (p->tempBufSize == 0) { SizeT processed; const Byte *bufLimit; if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) { int dummyRes = LzmaDec_TryDummy(p, src, inSize); if (dummyRes == DUMMY_ERROR) { memcpy(p->tempBuf, src, inSize); p->tempBufSize = (unsigned)inSize; (*srcLen) += inSize; *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (checkEndMarkNow && dummyRes != DUMMY_MATCH) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } bufLimit = src; } else bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX; p->buf = src; if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0) return SZ_ERROR_DATA; processed = p->buf - src; (*srcLen) += processed; src += processed; inSize -= processed; } else { unsigned rem = p->tempBufSize, lookAhead = 0; while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize) p->tempBuf[rem++] = src[lookAhead++]; p->tempBufSize = rem; if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) { int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem); if (dummyRes == DUMMY_ERROR) { (*srcLen) += lookAhead; *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (checkEndMarkNow && dummyRes != DUMMY_MATCH) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } } p->buf = p->tempBuf; if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0) return SZ_ERROR_DATA; lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf)); (*srcLen) += lookAhead; src += lookAhead; inSize -= lookAhead; p->tempBufSize = 0; } } if (p->code == 0) *status = LZMA_STATUS_FINISHED_WITH_MARK; return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; } SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) { SizeT outSize = *destLen; SizeT inSize = *srcLen; *srcLen = *destLen = 0; for (;;) { SizeT inSizeCur = inSize, outSizeCur, dicPos; ELzmaFinishMode curFinishMode; SRes res; if (p->dicPos == p->dicBufSize) p->dicPos = 0; dicPos = p->dicPos; if (outSize > p->dicBufSize - dicPos) { outSizeCur = p->dicBufSize; curFinishMode = LZMA_FINISH_ANY; } else { outSizeCur = dicPos + outSize; curFinishMode = finishMode; } res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status); src += inSizeCur; inSize -= inSizeCur; *srcLen += inSizeCur; outSizeCur = p->dicPos - dicPos; memcpy(dest, p->dic + dicPos, outSizeCur); dest += outSizeCur; outSize -= outSizeCur; *destLen += outSizeCur; if (res != 0) return res; if (outSizeCur == 0 || outSize == 0) return SZ_OK; } } void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) { alloc->Free(alloc, p->probs); p->probs = 0; } static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc) { alloc->Free(alloc, p->dic); p->dic = 0; } void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc) { LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeDict(p, alloc); } SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) { UInt32 dicSize; Byte d; if (size < LZMA_PROPS_SIZE) return SZ_ERROR_UNSUPPORTED; else dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24); if (dicSize < LZMA_DIC_MIN) dicSize = LZMA_DIC_MIN; p->dicSize = dicSize; d = data[0]; if (d >= (9 * 5 * 5)) return SZ_ERROR_UNSUPPORTED; p->lc = d % 9; d /= 9; p->pb = d / 5; p->lp = d % 5; return SZ_OK; } static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) { UInt32 numProbs = LzmaProps_GetNumProbs(propNew); if (p->probs == 0 || numProbs != p->numProbs) { LzmaDec_FreeProbs(p, alloc); p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); p->numProbs = numProbs; if (p->probs == 0) return SZ_ERROR_MEM; } return SZ_OK; } SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) { CLzmaProps propNew; RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); p->prop = propNew; return SZ_OK; } SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) { CLzmaProps propNew; SizeT dicBufSize; RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); dicBufSize = propNew.dicSize; if (p->dic == 0 || dicBufSize != p->dicBufSize) { LzmaDec_FreeDict(p, alloc); p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); if (p->dic == 0) { LzmaDec_FreeProbs(p, alloc); return SZ_ERROR_MEM; } } p->dicBufSize = dicBufSize; p->prop = propNew; return SZ_OK; } SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc) { CLzmaDec p; SRes res; SizeT inSize = *srcLen; SizeT outSize = *destLen; *srcLen = *destLen = 0; if (inSize < RC_INIT_SIZE) return SZ_ERROR_INPUT_EOF; LzmaDec_Construct(&p); res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc); if (res != 0) return res; p.dic = dest; p.dicBufSize = outSize; LzmaDec_Init(&p); *srcLen = inSize; res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status); if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT) res = SZ_ERROR_INPUT_EOF; (*destLen) = p.dicPos; LzmaDec_FreeProbs(&p, alloc); return res; } uif2iso-0.1.7a/src/compa.bat0000644000175100017510000000051311104342434014553 0ustar margamarga@echo off gcc -s -O2 -mtune=pentium -Wall -Wno-pointer-sign -Wunused -Wunused-function -Wunused-variable uif2iso.c d:\mingw\lib\libz.a d:\mingw\lib\libcomdlg32.a des.c 3way.c blowfish.c dunno.c gost.c idea.c loki91.c rc5.c seal.c lzmadec.c d:\mingw\lib\stristr.o ..\icon.o -o uif2iso.exe -DMAGICISO_IS_SHIT strip -s uif2iso.exe uif2iso-0.1.7a/src/Types.h0000644000175100017510000000504711070702744014256 0ustar margamarga/* Types.h -- Basic types 2008-04-11 Igor Pavlov Public domain */ #ifndef __7Z_TYPES_H #define __7Z_TYPES_H #define SZ_OK 0 #define SZ_ERROR_DATA 1 #define SZ_ERROR_MEM 2 #define SZ_ERROR_CRC 3 #define SZ_ERROR_UNSUPPORTED 4 #define SZ_ERROR_PARAM 5 #define SZ_ERROR_INPUT_EOF 6 #define SZ_ERROR_OUTPUT_EOF 7 #define SZ_ERROR_READ 8 #define SZ_ERROR_WRITE 9 #define SZ_ERROR_PROGRESS 10 #define SZ_ERROR_FAIL 11 #define SZ_ERROR_THREAD 12 #define SZ_ERROR_ARCHIVE 16 #define SZ_ERROR_NO_ARCHIVE 17 typedef int SRes; #ifndef RINOK #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } #endif typedef unsigned char Byte; typedef short Int16; typedef unsigned short UInt16; #ifdef _LZMA_UINT32_IS_ULONG typedef long Int32; typedef unsigned long UInt32; #else typedef int Int32; typedef unsigned int UInt32; #endif /* #define _SZ_NO_INT_64 */ /* define it if your compiler doesn't support 64-bit integers */ #ifdef _SZ_NO_INT_64 typedef long Int64; typedef unsigned long UInt64; #else #if defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 Int64; typedef unsigned __int64 UInt64; #else typedef long long int Int64; typedef unsigned long long int UInt64; #endif #endif #ifdef _LZMA_NO_SYSTEM_SIZE_T typedef UInt32 SizeT; #else #include typedef size_t SizeT; #endif typedef int Bool; #define True 1 #define False 0 #ifdef _MSC_VER #if _MSC_VER >= 1300 #define MY_NO_INLINE __declspec(noinline) #else #define MY_NO_INLINE #endif #define MY_CDECL __cdecl #define MY_STD_CALL __stdcall #define MY_FAST_CALL MY_NO_INLINE __fastcall #else #define MY_CDECL #define MY_STD_CALL #define MY_FAST_CALL #endif /* The following interfaces use first parameter as pointer to structure */ typedef struct { SRes (*Read)(void *p, void *buf, size_t *size); /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. (output(*size) < input(*size)) is allowed */ } ISeqInStream; typedef struct { size_t (*Write)(void *p, const void *buf, size_t size); /* Returns: result - the number of actually written bytes. (result < size) means error */ } ISeqOutStream; typedef struct { SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); /* Returns: result. (result != SZ_OK) means break. Value (UInt64)(Int64)-1 for size means unknown value. */ } ICompressProgress; typedef struct { void *(*Alloc)(void *p, size_t size); void (*Free)(void *p, void *address); /* address can be 0 */ } ISzAlloc; #define IAlloc_Alloc(p, size) (p)->Alloc((p), size) #define IAlloc_Free(p, a) (p)->Free((p), a) #endif uif2iso-0.1.7a/src/blowfish.h0000644000175100017510000000164711070523114014761 0ustar margamarga/* This code has been found on the website http://www.di-mgt.com.au/crypto.html The following is a small explanation from the website author: Here is Bruce Schneier's code in C for his Blowfish algorithm. This version is fully ANSI compliant and contains the "missing" P-box values omitted from the book. ... This code may be freely distributed. Updated 29 July 2003: thanks to Mehul Motani for pointing out an error in the code for readDataLine(). */ #include typedef struct { uint32_t S[4][256], P[18]; } blf_ctx; uint32_t F(blf_ctx *, uint32_t x); void Blowfish_encipher(blf_ctx *, uint32_t *xl, uint32_t *xr); void Blowfish_decipher(blf_ctx *, uint32_t *xl, uint32_t *xr); short InitializeBlowfish(blf_ctx *, unsigned char key[], int keybytes); void blf_enc(blf_ctx *c, uint32_t *data, int blocks); void blf_dec(blf_ctx *c, uint32_t *data, int blocks); void blf_key(blf_ctx *c, unsigned char *key, int len); uif2iso-0.1.7a/src/LzmaDec.h0000644000175100017510000001602211070702650014460 0ustar margamarga/* LzmaDec.h -- LZMA Decoder 2008-04-29 Copyright (c) 1999-2008 Igor Pavlov You can use any of the following license options: 1) GNU Lesser General Public License (GNU LGPL) 2) Common Public License (CPL) 3) Common Development and Distribution License (CDDL) Version 1.0 4) Igor Pavlov, as the author of this code, expressly permits you to statically or dynamically link your code (or bind by name) to this file, while you keep this file unmodified. */ #ifndef __LZMADEC_H #define __LZMADEC_H #include "Types.h" /* #define _LZMA_PROB32 */ /* _LZMA_PROB32 can increase the speed on some CPUs, but memory usage for CLzmaDec::probs will be doubled in that case */ #ifdef _LZMA_PROB32 #define CLzmaProb UInt32 #else #define CLzmaProb UInt16 #endif /* ---------- LZMA Properties ---------- */ #define LZMA_PROPS_SIZE 5 typedef struct _CLzmaProps { unsigned lc, lp, pb; UInt32 dicSize; } CLzmaProps; /* LzmaProps_Decode - decodes properties Returns: SZ_OK SZ_ERROR_UNSUPPORTED - Unsupported properties */ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); /* ---------- LZMA Decoder state ---------- */ /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ #define LZMA_REQUIRED_INPUT_MAX 20 typedef struct { CLzmaProps prop; CLzmaProb *probs; Byte *dic; const Byte *buf; UInt32 range, code; SizeT dicPos; SizeT dicBufSize; UInt32 processedPos; UInt32 checkDicSize; unsigned state; UInt32 reps[4]; unsigned remainLen; int needFlush; int needInitState; UInt32 numProbs; unsigned tempBufSize; Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; } CLzmaDec; #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } void LzmaDec_Init(CLzmaDec *p); /* There are two types of LZMA streams: 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ typedef enum { LZMA_FINISH_ANY, /* finish at any point */ LZMA_FINISH_END /* block must be finished at the end */ } ELzmaFinishMode; /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! You must use LZMA_FINISH_END, when you know that current output buffer covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, and output value of destLen will be less than output buffer size limit. You can check status result also. You can use multiple checks to test data integrity after full decompression: 1) Check Result and "status" variable. 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. You must use correct finish mode in that case. */ typedef enum { LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ } ELzmaStatus; /* ELzmaStatus is used only as output value for function call */ /* ---------- Interfaces ---------- */ /* There are 3 levels of interfaces: 1) Dictionary Interface 2) Buffer Interface 3) One Call Interface You can select any of these interfaces, but don't mix functions from different groups for same object. */ /* There are two variants to allocate state for Dictionary Interface: 1) LzmaDec_Allocate / LzmaDec_Free 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs You can use variant 2, if you set dictionary buffer manually. For Buffer Interface you must always use variant 1. LzmaDec_Allocate* can return: SZ_OK SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties */ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); /* ---------- Dictionary Interface ---------- */ /* You can use it, if you want to eliminate the overhead for data copying from dictionary to some other external buffer. You must work with CLzmaDec variables directly in this interface. STEPS: LzmaDec_Constr() LzmaDec_Allocate() for (each new stream) { LzmaDec_Init() while (it needs more decompression) { LzmaDec_DecodeToDic() use data from CLzmaDec::dic and update CLzmaDec::dicPos } } LzmaDec_Free() */ /* LzmaDec_DecodeToDic The decoding to internal dictionary buffer (CLzmaDec::dic). You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! finishMode: It has meaning only if the decoding reaches output limit (dicLimit). LZMA_FINISH_ANY - Decode just dicLimit bytes. LZMA_FINISH_END - Stream must be finished after dicLimit. Returns: SZ_OK status: LZMA_STATUS_FINISHED_WITH_MARK LZMA_STATUS_NOT_FINISHED LZMA_STATUS_NEEDS_MORE_INPUT LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK SZ_ERROR_DATA - Data error */ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); /* ---------- Buffer Interface ---------- */ /* It's zlib-like interface. See LzmaDec_DecodeToDic description for information about STEPS and return results, but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need to work with CLzmaDec variables manually. finishMode: It has meaning only if the decoding reaches output limit (*destLen). LZMA_FINISH_ANY - Decode just destLen bytes. LZMA_FINISH_END - Stream must be finished after (*destLen). */ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); /* ---------- One Call Interface ---------- */ /* LzmaDecode finishMode: It has meaning only if the decoding reaches output limit (*destLen). LZMA_FINISH_ANY - Decode just destLen bytes. LZMA_FINISH_END - Stream must be finished after (*destLen). Returns: SZ_OK status: LZMA_STATUS_FINISHED_WITH_MARK LZMA_STATUS_NOT_FINISHED LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK SZ_ERROR_DATA - Data error SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). */ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); #endif uif2iso-0.1.7a/src/magiciso_is_shit.h0000644000175100017510000003714011070705774016474 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ #ifdef MAGICISO_IS_SHIT void x3way(uint8_t *data, int datalen, uint32_t *key); #define WORDS_PER_SEAL_CALL 1024 typedef struct { uint32_t t[520]; /* 512 rounded up to a multiple of 5 + 5*/ uint32_t s[265]; /* 256 rounded up to a multiple of 5 + 5*/ uint32_t r[20]; /* 16 rounded up to multiple of 5 */ uint32_t counter; /* 32-bit synch value. */ uint32_t ks_buf[WORDS_PER_SEAL_CALL]; int ks_pos; } seal_ctx; void seal_key(seal_ctx *c, unsigned char *key); void seal_encrypt(seal_ctx *c, uint32_t *data_ptr, int w); void seal_decrypt(seal_ctx *c, uint32_t *data_ptr, int w); void RC5decrypt(uint32_t *in, int len, int b, uint32_t *key); void RC5key(unsigned char *key, int b, uint32_t **ctx); #include "loki.h" #define IDEA_ROUNDS 8 #define IDEA_KEYLEN (6*IDEA_ROUNDS+4) typedef struct { u16 ek[IDEA_KEYLEN]; u16 dk[IDEA_KEYLEN]; int have_dk; } IDEA_context; int do_setkey( IDEA_context *c, u8 *key, unsigned keylen ); void encrypt_block( IDEA_context *bc, u8 *outbuf, u8 *inbuf ); void decrypt_block( IDEA_context *bc, u8 *outbuf, u8 *inbuf ); void kboxinit(void); void gostdecrypt(uint32_t const in[2], uint32_t out[2], uint32_t const key[8]); #include "blowfish.h" void dunno_key(uint32_t *dunnoctx, char *key); void dunno_dec(uint32_t *dunnoctx, uint8_t *data, int datalen); static const u8 magiciso_is_shit_sbox[1920] = { 0x68,0x5a,0x3d,0xe9,0xf7,0x40,0x81,0x94,0x1c,0x26,0x4c,0xf6,0x34,0x29,0x69,0x94, 0xf7,0x20,0x15,0x41,0xf7,0xd4,0x02,0x76,0x2e,0x6b,0xf4,0xbc,0x68,0x00,0xa2,0xd4, 0x71,0x24,0x08,0xd4,0x6a,0xf4,0x20,0x33,0xb7,0xd4,0xb7,0x43,0xaf,0x61,0x00,0x50, 0x2e,0xf6,0x39,0x1e,0x46,0x45,0x24,0x97,0x74,0x4f,0x21,0x14,0x40,0x88,0x8b,0xbf, 0x1d,0xfc,0x95,0x4d,0xaf,0x91,0xb5,0x96,0xd3,0xdd,0xf4,0x70,0x45,0x2f,0xa0,0x66, 0xec,0x09,0xbc,0xbf,0x85,0x97,0xbd,0x03,0xd0,0x6d,0xac,0x7f,0x04,0x85,0xcb,0x31, 0xb3,0x27,0xeb,0x96,0x41,0x39,0xfd,0x55,0xe6,0x47,0x25,0xda,0x9a,0x0a,0xca,0xab, 0x25,0x78,0x50,0x28,0xf4,0x29,0x04,0x53,0xda,0x86,0x2c,0x0a,0x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a,0xc6,0xcc,0x4c,0x75,0x12,0x1c,0xf1,0x2e,0x78, 0x37,0x42,0x12,0x6a,0xe7,0x51,0x92,0xb7,0xe6,0xbb,0xa1,0x06,0x50,0x63,0xfb,0x4b, 0x18,0x10,0x6b,0x1a,0xfa,0xed,0xca,0x11,0xd8,0xbd,0x25,0x3d,0xc9,0xc3,0xe1,0xe2, 0x59,0x16,0x42,0x44,0x86,0x13,0x12,0x0a,0x6e,0xec,0x0c,0xd9,0x2a,0xea,0xab,0xd5, 0x4e,0x67,0xaf,0x64,0x5f,0xa8,0x86,0xda,0x88,0xe9,0xbf,0xbe,0xfe,0xc3,0xe4,0x64, 0x57,0x80,0xbc,0x9d,0x86,0xc0,0xf7,0xf0,0xf8,0x7b,0x78,0x60,0x4d,0x60,0x03,0x60, 0x46,0x83,0xfd,0xd1,0xb0,0x1f,0x38,0xf6,0x04,0xae,0x45,0x77,0xcc,0xfc,0x36,0xd7, 0x33,0x6b,0x42,0x83,0x71,0xab,0x1e,0xf0,0x87,0x41,0x80,0xb0,0x5f,0x5e,0x00,0x3c, 0xbe,0x57,0xa0,0x77,0x24,0xae,0xe8,0xbd,0x99,0x42,0x46,0x55,0x61,0x2e,0x58,0xbf, 0x8f,0xf4,0x58,0x4e,0xa2,0xfd,0xdd,0xf2,0x38,0xef,0x74,0xf4,0xc2,0xbd,0x89,0x87, 0xc3,0xf9,0x66,0x53,0x74,0x8e,0xb3,0xc8,0x55,0xf2,0x75,0xb4,0xb9,0xd9,0xfc,0x46, 0x61,0x26,0xeb,0x7a,0x84,0xdf,0x1d,0x8b,0x79,0x0e,0x6a,0x84,0xe2,0x95,0x5f,0x91, 0x8e,0x59,0x6e,0x46,0x70,0x57,0xb4,0x20,0x91,0x55,0xd5,0x8c,0x4c,0xde,0x02,0xc9, 0xe1,0xac,0x0b,0xb9,0xd0,0x05,0x82,0xbb,0x48,0x62,0xa8,0x11,0x9e,0xa9,0x74,0x75, 0xb6,0x19,0x7f,0xb7,0x09,0xdc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,0x81,0x1b,0x90,0x50,0x4c,0x14,0x56,0xc6,0x71, 0xbd,0xc7,0xc6,0xe6,0x0a,0x14,0x7a,0x32,0x06,0xd0,0xe1,0x45,0x9a,0x7b,0xf2,0xc3 }; typedef struct { IDEA_context ideactx; seal_ctx sealctx; blf_ctx blfctx; u32 dunnoctx[6]; u32 x3wayctx[3]; u32 gostctx[8]; u32 *rc5ctx; u32 lokictx[ROUNDS]; u8 *key; u8 flag; u8 *easy_reset; // lazy solution } magiciso_is_shit_ctx_t; #define magiciso_is_shit_ctx_t_size ((u8 *)&(ctx->easy_reset) - (u8 *)ctx) const u8 *magiciso_is_shit_getkey(int num) { if(endian) { printf("\n" "Error: the magiciso_is_shit encryption can't work on your system\n" "\n"); myexit(); } return(magiciso_is_shit_sbox + ((num & 0x0f) << (3 + 2 + 2))); } void magiciso_is_shit_key(magiciso_is_shit_ctx_t *ctx, int num) { u8 tmpkey[32]; if(!ctx) return; ctx->key = (u8 *)magiciso_is_shit_getkey(num); memcpy(tmpkey, ctx->key, 32); // avoids possible read-only problems if(ctx->flag & 0x01) { memcpy((void *)ctx->x3wayctx, tmpkey, 12); } if(ctx->flag & 0x02) { dunno_key(ctx->dunnoctx, tmpkey); } if(ctx->flag & 0x04) { InitializeBlowfish(&ctx->blfctx, tmpkey, 16); } if(ctx->flag & 0x08) { kboxinit(); memcpy(ctx->gostctx, tmpkey, 32); } if(ctx->flag & 0x10) { do_setkey(&ctx->ideactx, tmpkey, 16); } if(ctx->flag & 0x20) { setlokikey(ctx->lokictx, tmpkey); } if(ctx->flag & 0x40) { RC5key(tmpkey, 5, &ctx->rc5ctx); } if(ctx->flag & 0x80) { seal_key(&ctx->sealctx, tmpkey); } ctx->easy_reset = malloc(magiciso_is_shit_ctx_t_size); memcpy(ctx->easy_reset, ctx, magiciso_is_shit_ctx_t_size); } void magiciso_is_shit_reset(magiciso_is_shit_ctx_t *ctx) { // easy solution if(!ctx) return; memcpy(ctx, ctx->easy_reset, magiciso_is_shit_ctx_t_size); } void magiciso_is_shit_free(magiciso_is_shit_ctx_t *ctx) { if(!ctx) return; free(ctx->easy_reset); free(ctx); } void magiciso_is_shit_dec(magiciso_is_shit_ctx_t *ctx, u8 *data, int datalen) { int i; if(!ctx) return; datalen &= ~7; magiciso_is_shit_reset(ctx); if(ctx->flag & 0x01) { x3way(data, datalen, ctx->x3wayctx); } if(ctx->flag & 0x80) { seal_decrypt(&ctx->sealctx, (u32 *)data, datalen >> 2); } if(ctx->flag & 0x40) { RC5decrypt((u32 *)data, datalen >> 3, 5, ctx->rc5ctx); } if(ctx->flag & 0x20) { for(i = 0; i < datalen; i += 8) { deloki(ctx->lokictx, data + i); } } if(ctx->flag & 0x10) { for(i = 0; i < datalen; i += 8) { decrypt_block(&ctx->ideactx, data + i, data + i); } } if(ctx->flag & 0x08) { kboxinit(); for(i = 0; i < datalen; i += 8) { gostdecrypt((u32 *)(data + i), (u32 *)(data + i), (void *)ctx->gostctx); } } if(ctx->flag & 0x04) { blf_dec(&ctx->blfctx, (u32 *)data, datalen >> 3); } if(ctx->flag & 0x02) { dunno_dec(ctx->dunnoctx, data, datalen); } } #else typedef struct { u8 *key; u8 flag; } magiciso_is_shit_ctx_t; const u8 *magiciso_is_shit_getkey(int num) { return(NULL); } void magiciso_is_shit_key(magiciso_is_shit_ctx_t *ctx, int num) { printf("\n" "Error: this executable has been compiled without support for magiciso_is_shit\n" "\n"); myexit(); } void magiciso_is_shit_reset(magiciso_is_shit_ctx_t *ctx) { // easy solution if(!ctx) return; } void magiciso_is_shit_free(magiciso_is_shit_ctx_t *ctx) { if(!ctx) return; } void magiciso_is_shit_dec(magiciso_is_shit_ctx_t *ctx, u8 *data, int datalen) { if(!ctx) return; } #endif uif2iso-0.1.7a/src/loki.h0000644000175100017510000000614611130672204014103 0ustar margamarga/* Copyright (C) 2008,2009 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* * loki.h - specifies the interface to the LOKI encryption routines. * This library proviloki routines to expand a key, encrypt and * decrypt 64-bit data blocks. The LOKI Data Encryption Algorithm * is a block cipher which ensures that its output is a complex * function of its input and the key. * * Authors: Lawrie Brown Aug 1989 * Matthew Kwan Sep 1991 * * Computer Science, UC UNSW, Australian Defence Force Academy, * Canberra, ACT 2600, Australia. * * Version: * v1.0 - of loki64.o is current 7/89 lpb * v2.0 - of loki64.c is current 9/91 mkwan * v3.0 - now have loki89.c & loki91.c 10/92 lpb * * Copyright 1989 by Lawrie Brown and UNSW. All rights reserved. * This program may not be sold or used as inducement to buy a * product without the written permission of the author. * * Description: * The routines provided by the library are: * * lokikey(key) - expands a key into subkey, for use in * char key[8]; encryption and decryption operations. * * enloki(b) - main LOKI encryption routine, this routine * char b[8]; encrypts one 64-bit block b with subkey * * deloki(b) - main LOKI decryption routine, this routine * char b[8]; decrypts one 64-bit block b with subkey * * The 64-bit data & key blocks used in the algorithm are specified as eight * unsigned chars. For the purposes of implementing the LOKI algorithm, * these MUST be word aligned with bits are numbered as follows: * [63..56] [55..48] ... [7..0] * in b[0] b[1] b[2] b[3] b[4] b[5] b[6] b[7] */ #include #define LOKIBLK 8 /* No of bytes in a LOKI data-block */ #define ROUNDS 16 /* No of LOKI rounds */ typedef uint32_t Long; /* type specification for aligned LOKI blocks */ extern Long lokikey[2]; /* 64-bit key used by LOKI routines */ extern char *loki_lib_ver; /* String with version no. & copyright */ //#ifdef __STDC__ /* declare prototypes for library functions */ extern void enloki(Long loki_subkeys[ROUNDS], char b[LOKIBLK]); extern void deloki(Long loki_subkeys[ROUNDS], char b[LOKIBLK]); extern void setlokikey(Long loki_subkeys[ROUNDS], char key[LOKIBLK]); //#else /* else just declare library functions extern */ //extern void enloki(), deloki(), setlokikey(); //#endif __STDC__ uif2iso-0.1.7a/src/idea.c0000644000175100017510000002414711070743700014046 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* idea.c - IDEA function * Copyright (c) 1997,1998,1999 by Werner Koch (dd9jn) ************************************************************************ * ATTENTION: The used algorithm is patented and may need a license for any use. See below for more information. ************************************************************************ * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * WERNER KOCH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Werner Koch shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from Werner Koch. */ /*-------------------------------------------------------------- The code herein has been taken from: Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. ISBN 0-471-11709-9. . The IDEA algorithm is patented by Ascom Systec Ltd. of CH-5506 Maegenwil, Switzerland, who allow it to be used on a royalty-free basis for certain non-profit applications. Commercial users must obtain a license from the company in order to use IDEA. IDEA may be used on a royalty-free basis under the following conditions: Free use for private purposes: The free use of software containing the algorithm is strictly limited to non revenue generating data transfer between private individuals, ie not serving commercial purposes. Requests by freeware developers to obtain a royalty-free license to spread an application program containing the algorithm for non-commercial purposes must be directed to Ascom. Special offer for shareware developers: There is a special waiver for shareware developers. Such waiver eliminates the upfront fees as well as royalties for the first US$10,000 gross sales of a product containing the algorithm if and only if: 1. The product is being sold for a minimum of US$10 and a maximum of US$50. 2. The source code for the shareware is available to the public. Special conditions for research projects: The use of the algorithm in research projects is free provided that it serves the purpose of such project and within the project duration. Any use of the algorithm after the termination of a project including activities resulting from a project and for purposes not directly related to the project requires a license. Ascom Tech requires the following notice to be included for freeware products: This software product contains the IDEA algorithm as described and claimed in US patent 5,214,703, EPO patent 0482154 (covering Austria, France, Germany, Italy, the Netherlands, Spain, Sweden, Switzerland, and the UK), and Japanese patent application 508119/1991, "Device for the conversion of a digital block and use of same" (hereinafter referred to as "the algorithm"). Any use of the algorithm for commercial purposes is thus subject to a license from Ascom Systec Ltd. of CH-5506 Maegenwil (Switzerland), being the patentee and sole owner of all rights, including the trademark IDEA. Commercial purposes shall mean any revenue generating purpose including but not limited to: i) Using the algorithm for company internal purposes (subject to a site license). ii) Incorporating the algorithm into any software and distributing such software and/or providing services relating thereto to others (subject to a product license). iii) Using a product containing the algorithm not covered by an IDEA license (subject to an end user license). All such end user license agreements are available exclusively from Ascom Systec Ltd and may be requested via the WWW at http://www.ascom.ch/systec or by email to idea@ascom.ch. Use other than for commercial purposes is strictly limited to non-revenue generating data transfer between private individuals. The use by government agencies, non-profit organizations, etc is considered as use for commercial purposes but may be subject to special conditions. Any misuse will be prosecuted. -------------------------------------------------------------------*/ /* How to compile: * gcc -Wall -O2 -shared -fPIC -o idea idea.c */ #include #include #include #include /* configuration stuff */ #ifdef __alpha__ #define SIZEOF_UNSIGNED_LONG 8 #else #define SIZEOF_UNSIGNED_LONG 4 #endif #if defined(__mc68000__) || defined (__sparc__) || defined (__PPC__) \ || (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)) ) \ || defined(__hpux__) /* should be replaced by the Macro for the PA */ #define BIG_ENDIAN_HOST 1 #else #define LITTLE_ENDIAN_HOST 1 #endif typedef unsigned char byte; typedef uint16_t u16; typedef uint32_t u32; /* end configurable stuff */ #ifndef DIM #define DIM(v) (sizeof(v)/sizeof((v)[0])) #define DIMof(type,member) DIM(((type *)0)->member) #endif /* imports */ void g10_log_fatal( const char *fmt, ... ); /* local stuff */ #define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f)) #define FNCCAST_CRYPT(f) ((void(*)(void*, byte*, byte*))(f)) #define IDEA_KEYSIZE 16 #define IDEA_BLOCKSIZE 8 #define IDEA_ROUNDS 8 #define IDEA_KEYLEN (6*IDEA_ROUNDS+4) typedef struct { u16 ek[IDEA_KEYLEN]; u16 dk[IDEA_KEYLEN]; int have_dk; } IDEA_context; int do_setkey( IDEA_context *c, byte *key, unsigned keylen ); void encrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); void decrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); u16 mul_inv( u16 x ) { u16 t0, t1; u16 q, y; if( x < 2 ) return x; t1 = 0x10001L / x; y = 0x10001L % x; if( y == 1 ) return (1-t1) & 0xffff; t0 = 1; do { q = x / y; x = x % y; t0 += q * t1; if( x == 1 ) return t0; q = y / x; y = y % x; t1 += q * t0; } while( y != 1 ); return (1-t1) & 0xffff; } void expand_key( byte *userkey, u16 *ek ) { int i,j; for(j=0; j < 8; j++ ) { ek[j] = (*userkey << 8) + userkey[1]; userkey += 2; } for(i=0; j < IDEA_KEYLEN; j++ ) { i++; ek[i+7] = ek[i&7] << 9 | ek[(i+1)&7] >> 7; ek[i+7] ^= 0x28fc; ek += i & 8; i &= 7; } } void invert_key( u16 *ek, u16 dk[IDEA_KEYLEN] ) { int i; u16 t1, t2, t3; u16 temp[IDEA_KEYLEN]; u16 *p = temp + IDEA_KEYLEN; t1 = mul_inv( *ek++ ); t2 = -*ek++; t3 = -*ek++; *--p = mul_inv( *ek++ ); *--p = t3; *--p = t2; *--p = t1; for(i=0; i < IDEA_ROUNDS-1; i++ ) { t1 = *ek++; *--p = *ek++; *--p = t1; t1 = mul_inv( *ek++ ); t2 = -*ek++; t3 = -*ek++; *--p = mul_inv( *ek++ ); *--p = t2; *--p = t3; *--p = t1; } t1 = *ek++; *--p = *ek++; *--p = t1; t1 = mul_inv( *ek++ ); t2 = -*ek++; t3 = -*ek++; *--p = mul_inv( *ek++ ); *--p = t3; *--p = t2; *--p = t1; memcpy(dk, temp, sizeof(temp) ); } void cipher( byte *outbuf, byte *inbuf, u16 *key ) { u16 x1, x2, x3,x4, s2, s3; u16 *in, *out; int r = IDEA_ROUNDS; #define MUL(x,y) \ do {u16 _t16; u32 _t32; \ if( (_t16 = (y)) ) { \ if( (x = (x)&0xffff) ) { \ _t32 = (u32)x * _t16; \ x = _t32 & 0xffff; \ _t16 = _t32 >> 16; \ x = ((x)-_t16) + (x<_t16?1:0); \ } \ else { \ x = 1 - _t16; \ } \ } \ else { \ x = 1 - x; \ } \ } while(0) in = (u16*)inbuf; x1 = *in++; x2 = *in++; x3 = *in++; x4 = *in; #ifndef LITTLE_ENDIAN_HOST x1 = (x1>>8) | (x1<<8); x2 = (x2>>8) | (x2<<8); x3 = (x3>>8) | (x3<<8); x4 = (x4>>8) | (x4<<8); #endif do { MUL(x1, *key++); x2 += *key++; x3 += *key++; MUL(x4, *key++ ); s3 = x3; x3 ^= x1; MUL(x3, *key++); s2 = x2; x2 ^=x4; x2 += x3; MUL(x2, *key++); x3 += x2; x1 ^= x2; x4 ^= x3; x2 ^= s3; x3 ^= s2; } while( --r ); MUL(x1, *key++); x3 += *key++; x2 += *key++; MUL(x4, *key); out = (u16*)outbuf; #ifndef LITTLE_ENDIAN_HOST *out++ = (x1>>8) | (x1<<8); *out++ = (x3>>8) | (x3<<8); *out++ = (x2>>8) | (x2<<8); *out = (x4>>8) | (x4<<8); #else *out++ = x1; *out++ = x3; *out++ = x2; *out = x4; #endif #undef MUL } int do_setkey( IDEA_context *c, byte *key, unsigned keylen ) { c->have_dk = 0; expand_key( key, c->ek ); invert_key( c->ek, c->dk ); return 0; } void encrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) { cipher( outbuf, inbuf, c->ek ); } void decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) { if( !c->have_dk ) { c->have_dk = 1; invert_key( c->ek, c->dk ); } cipher( outbuf, inbuf, c->dk ); } uif2iso-0.1.7a/src/3way.c0000644000175100017510000000652111070743130014020 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO #include #include #include #define STRT_E 0x0b0b #define STRT_D 0xb1b1 #define NMBR 11 void xtheta(uint32_t *a) { uint32_t b[3]; b[0] = a[0] ^ (a[0]>>16) ^ (a[1]<<16) ^ (a[1]>>16) ^ (a[2]<<16) ^ (a[1]>>24) ^ (a[2]<<8) ^ (a[2]>>8) ^ (a[0]<<24) ^ (a[2]>>16) ^ (a[0]<<16) ^ (a[2]>>24) ^ (a[0]<<8); b[1] = a[1] ^ (a[1]>>16) ^ (a[2]<<16) ^ (a[2]>>16) ^ (a[0]<<16) ^ (a[2]>>24) ^ (a[0]<<8) ^ (a[0]>>8) ^ (a[1]<<24) ^ (a[0]>>16) ^ (a[1]<<16) ^ (a[0]>>24) ^ (a[1]<<8); b[2] = a[2] ^ (a[2]>>16) ^ (a[0]<<16) ^ (a[0]>>16) ^ (a[1]<<16) ^ (a[0]>>24) ^ (a[1]<<8) ^ (a[1]>>8) ^ (a[2]<<24) ^ (a[1]>>16) ^ (a[2]<<16) ^ (a[1]>>24) ^ (a[2]<<8); a[0] = b[0]; a[1] = b[1]; a[2] = b[2]; } void xpi1(uint32_t *p) { p[0] = (p[0] >> 0x0a) ^ (p[0] << 0x16); p[2] = (p[2] >> 0x1f) ^ (p[2] << 1); } void xgamma(uint32_t *p) { uint32_t tmp[3]; tmp[0] = p[0]; tmp[1] = p[1]; tmp[2] = p[2]; p[0] ^= (~tmp[2]) | tmp[1]; p[1] ^= (~tmp[0]) | tmp[2]; p[2] ^= (~tmp[1]) | tmp[0]; } void xpi2(uint32_t *p) { p[2] = (p[2] >> 0x0a) ^ (p[2] << 0x16); p[0] = (p[0] >> 0x1f) ^ (p[0] << 1); } void xrho(uint32_t *p) { xtheta(p); xpi1(p); xgamma(p); xpi2(p); } void xmu(uint32_t *p) { uint32_t bswap[3]; int i; bswap[0] = 0; bswap[1] = 0; bswap[2] = 0; for(i = 0; i < 32; i++) { bswap[0] <<= 1; bswap[1] <<= 1; bswap[2] <<= 1; if(p[0] & 1) bswap[2] |= 1; if(p[1] & 1) bswap[1] |= 1; if(p[2] & 1) bswap[0] |= 1; p[0] >>= 1; p[1] >>= 1; p[2] >>= 1; } p[0] = bswap[0]; p[1] = bswap[1]; p[2] = bswap[2]; } void xrndcon_gen(uint32_t strt,uint32_t *rtab) { int i; for(i = 0; i <= NMBR; i++) { rtab[i] = strt; strt <<= 1; if(strt & 0x10000) strt ^= 0x11011; } } void x3way(uint8_t *data, int datalen, uint32_t *key) { uint32_t rcon[NMBR+1], *p; int i; xtheta(key); xmu(key); xrndcon_gen(STRT_D, rcon); datalen /= 12; for(p = (uint32_t *)data; datalen--; p += 3) { p[2] ^= p[0]; p[0] ^= p[1]; p[1] ^= 0x7483a3fd; xmu(p); for(i = 0; i < 11; i++) { p[0] ^= key[0] ^ (rcon[i] << 16); p[1] ^= key[1]; p[2] ^= key[2] ^ rcon[i]; xrho(p); } p[0] ^= key[0] ^ (rcon[NMBR] << 16); p[1] ^= key[1]; p[2] ^= key[2] ^ rcon[NMBR]; xtheta(p); xmu(p); } } uif2iso-0.1.7a/src/gost.c0000644000175100017510000002636411070743224014124 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* * The GOST 28147-89 cipher * * This is based on the 25 Movember 1993 draft translation * by Aleksandr Malchik, with Whitfield Diffie, of the Government * Standard of the U.S.S.R. GOST 28149-89, "Cryptographic Transformation * Algorithm", effective 1 July 1990. (Whitfield.Diffie@eng.sun.com) * * That is a draft, and may contain errors, which will be faithfully * reflected here, along with possible exciting new bugs. * * Some details have been cleared up by the paper "Soviet Encryption * Algorithm" by Josef Pieprzyk and Leonid Tombak of the University * of Wollongong, New South Wales. (josef/leo@cs.adfa.oz.au) * * The standard is written by A. Zabotin (project leader), G.P. Glazkov, * and V.B. Isaeva. It was accepted and introduced into use by the * action of the State Standards Committee of the USSR on 2 June 89 as * No. 1409. It was to be reviewed in 1993, but whether anyone wishes * to take on this obligation from the USSR is questionable. * * This code is placed in the public domain. */ /* * If you read the standard, it belabors the point of copying corresponding * bits from point A to point B quite a bit. It helps to understand that * the standard is uniformly little-endian, although it numbers bits from * 1 rather than 0, so bit n has value 2^(n-1). The least significant bit * of the 32-bit words that are manipulated in the algorithm is the first, * lowest-numbered, in the bit string. */ #include #include /* A 32-bit data type */ #ifdef __alpha /* Any other 64-bit machines? */ typedef unsigned int word32; #else typedef uint32_t word32; #endif /* * The standard does not specify the contents of the 8 4 bit->4 bit * substitution boxes, saying they're a parameter of the network * being set up. For illustration purposes here, I have used * the first rows of the 8 S-boxes from the DES. (Note that the * DES S-boxes are numbered starting from 1 at the msb. In keeping * with the rest of the GOST, I have used little-endian numbering. * Thus, k8 is S-box 1. * * Obviously, a careful look at the cryptographic properties of the cipher * must be undertaken before "production" substitution boxes are defined. * * The standard also does not specify a standard bit-string representation * for the contents of these blocks. */ static unsigned char const k8[16] = { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }; static unsigned char const k7[16] = { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }; static unsigned char const k6[16] = { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }; static unsigned char const k5[16] = { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }; static unsigned char const k4[16] = { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }; static unsigned char const k3[16] = { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }; static unsigned char const k2[16] = { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }; static unsigned char const k1[16] = { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }; /* Byte-at-a-time substitution boxes */ static unsigned char k87[256]; static unsigned char k65[256]; static unsigned char k43[256]; static unsigned char k21[256]; /* * Build byte-at-a-time subtitution tables. * This must be called once for global setup. */ void kboxinit(void) { int i; for (i = 0; i < 256; i++) { k87[i] = k8[i >> 4] << 4 | k7[i & 15]; k65[i] = k6[i >> 4] << 4 | k5[i & 15]; k43[i] = k4[i >> 4] << 4 | k3[i & 15]; k21[i] = k2[i >> 4] << 4 | k1[i & 15]; } } /* * Do the substitution and rotation that are the core of the operation, * like the expansion, substitution and permutation of the DES. * It would be possible to perform DES-like optimisations and store * the table entries as 32-bit words, already rotated, but the * efficiency gain is questionable. * * This should be inlined for maximum speed */ #if __GNUC__ __inline__ #endif static word32 f(word32 x) { /* Do substitutions */ #if 0 /* This is annoyingly slow */ x = k8[x>>28 & 15] << 28 | k7[x>>24 & 15] << 24 | k6[x>>20 & 15] << 20 | k5[x>>16 & 15] << 16 | k4[x>>12 & 15] << 12 | k3[x>> 8 & 15] << 8 | k2[x>> 4 & 15] << 4 | k1[x & 15]; #else /* This is faster */ x = (char)k87[x>>24 & 255] << 24 | (char)k65[x>>16 & 255] << 16 | (char)k43[x>> 8 & 255] << 8 | (char)k21[x & 255]; #endif /* Rotate left 11 bits */ return x<<11 | x>>(32-11); } /* * The GOST standard defines the input in terms of bits 1..64, with * bit 1 being the lsb of in[0] and bit 64 being the msb of in[1]. * * The keys are defined similarly, with bit 256 being the msb of key[7]. */ void gostcrypt(word32 const in[2], word32 out[2], word32 const key[8]) { register word32 n1, n2; /* As named in the GOST */ n1 = in[0]; n2 = in[1]; /* Instead of swapping halves, swap names each round */ n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); n2 ^= f(n1+key[7]); n1 ^= f(n2+key[6]); n2 ^= f(n1+key[5]); n1 ^= f(n2+key[4]); n2 ^= f(n1+key[3]); n1 ^= f(n2+key[2]); n2 ^= f(n1+key[1]); n1 ^= f(n2+key[0]); /* There is no swap after the last round */ out[0] = n2; out[1] = n1; } /* * The key schedule is somewhat different for decryption. * (The key table is used once forward and three times backward.) * You could define an expanded key, or just write the code twice, * as done here. */ void gostdecrypt(word32 const in[2], word32 out[2], word32 const key[8]) { register word32 n1, n2; /* As named in the GOST */ n1 = in[0]; n2 = in[1]; n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); n2 ^= f(n1+key[7]); n1 ^= f(n2+key[6]); // n2 ^= f(n1+key[5]); // n1 ^= f(n2+key[4]); n2 ^= f(n1+key[3]); n1 ^= f(n2+key[2]); n2 ^= f(n1+key[1]); n1 ^= f(n2+key[0]); // n2 ^= f(n1+key[7]); // n1 ^= f(n2+key[6]); n2 ^= f(n1+key[5]); n1 ^= f(n2+key[4]); n2 ^= f(n1+key[3]); n1 ^= f(n2+key[2]); n2 ^= f(n1+key[1]); n1 ^= f(n2+key[0]); n2 ^= f(n1+key[7]); n1 ^= f(n2+key[6]); n2 ^= f(n1+key[5]); n1 ^= f(n2+key[4]); n2 ^= f(n1+key[3]); n1 ^= f(n2+key[2]); n2 ^= f(n1+key[1]); n1 ^= f(n2+key[0]); out[0] = n2; out[1] = n1; } /* * The GOST "Output feedback" standard. It seems closer morally * to the counter feedback mode some people have proposed for DES. * The avoidance of the short cycles that are possible in OFB seems * like a Good Thing. * * Calling it the stream mode makes more sense. * * The IV is encrypted with the key to produce the initial counter value. * Then, for each output block, a constant is added, modulo 2^32-1 * (0 is represented as all-ones, not all-zeros), to each half of * the counter, and the counter is encrypted to produce the value * to XOR with the output. * * Len is the number of blocks. Sub-block encryption is * left as an exercise for the user. Remember that the * standard defines everything in a little-endian manner, * so you want to use the low bit of gamma[0] first. * * OFB is, of course, self-inverse, so there is only one function. */ /* The constants for addition */ #define C1 0x01010104 #define C2 0x01010101 void gostofb(word32 const *in, word32 *out, int len, word32 const iv[2], word32 const key[8]) { word32 temp[2]; /* Counter */ word32 gamma[2]; /* Output XOR value */ /* Compute starting value for counter */ gostcrypt(iv, temp, key); while (len--) { temp[0] += C2; if (temp[0] < C2) /* Wrap modulo 2^32? */ temp[0]++; /* Make it modulo 2^32-1 */ temp[1] += C1; if (temp[1] < C1) /* Wrap modulo 2^32? */ temp[1]++; /* Make it modulo 2^32-1 */ gostcrypt(temp, gamma, key); *out++ = *in++ ^ gamma[0]; *out++ = *in++ ^ gamma[1]; } } /* * The CFB mode is just what you'd expect. Each block of ciphertext y[] is * derived from the input x[] by the following pseudocode: * y[i] = x[i] ^ gostcrypt(y[i-1]) * x[i] = y[i] ^ gostcrypt(y[i-1]) * Where y[-1] is the IV. * * The IV is modified in place. Again, len is in *blocks*. */ void gostcfbencrypt(word32 const *in, word32 *out, int len, word32 iv[2], word32 const key[8]) { while (len--) { gostcrypt(iv, iv, key); iv[0] = *out++ ^= iv[0]; iv[1] = *out++ ^= iv[1]; } } void gostcfbdecrypt(word32 const *in, word32 *out, int len, word32 iv[2], word32 const key[8]) { word32 t; while (len--) { gostcrypt(iv, iv, key); t = *out; *out++ ^= iv[0]; iv[0] = t; t = *out; *out++ ^= iv[1]; iv[1] = t; } } /* * The message suthetication code uses only 16 of the 32 rounds. * There *is* a swap after the 16th round. * The last block should be padded to 64 bits with zeros. * len is the number of *blocks* in the input. */ void gostmac(word32 const *in, int len, word32 out[2], word32 const key[8]) { register word32 n1, n2; /* As named in the GOST */ n1 = 0; n2 = 0; while (len--) { n1 ^= *in++; n2 = *in++; /* Instead of swapping halves, swap names each round */ n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); n2 ^= f(n1+key[0]); n1 ^= f(n2+key[1]); n2 ^= f(n1+key[2]); n1 ^= f(n2+key[3]); n2 ^= f(n1+key[4]); n1 ^= f(n2+key[5]); n2 ^= f(n1+key[6]); n1 ^= f(n2+key[7]); } out[0] = n1; out[1] = n2; } #ifdef TEST #include #include /* Designed to cope with 15-bit rand() implementations */ #define RAND32 ((word32)rand() << 17 ^ (word32)rand() << 9 ^ rand()) int main(void) { word32 key[8]; word32 plain[2]; word32 cipher[2]; int i, j; kboxinit(); printf("GOST 21847-89 test driver.\n"); for (i = 0; i < 1000; i++) { for (j = 0; j < 8; j++) key[j] = RAND32; plain[0] = RAND32; plain[1] = RAND32; printf("%3d\r", i); fflush(stdout); gostcrypt(plain, cipher, key); for (j = 0; j < 99; j++) gostcrypt(cipher, cipher, key); for (j = 0; j < 100; j++) gostdecrypt(cipher, cipher, key); if (plain[0] != cipher[0] || plain[1] != cipher[1]) { fprintf(stderr, "\nError! i = %d\n", i); return 1; } } printf("All tests passed.\n"); return 0; } #endif /* TEST */ uif2iso-0.1.7a/src/bf_tab.h0000644000175100017510000003263311070742644014373 0ustar margamarga/* This code has been found on the website http://www.di-mgt.com.au/crypto.html The following is a small explanation from the website author: Here is Bruce Schneier's code in C for his Blowfish algorithm. This version is fully ANSI compliant and contains the "missing" P-box values omitted from the book. ... This code may be freely distributed. Updated 29 July 2003: thanks to Mehul Motani for pointing out an error in the code for readDataLine(). */ /* bf_tab.h: Blowfish P-box and S-box tables */ /* static uint32_t bfp[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b, }; */ static uint32_t ks0[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a }; static uint32_t ks1[]= { 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 }; static uint32_t ks2[] = { 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 }; static uint32_t ks3[] = { 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 }; uif2iso-0.1.7a/src/rc5.c0000644000175100017510000000425511070743700013633 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // Code modified by Luigi Auriemma. for emulating the shameful customizations of MagicISO // Code derived from the reference implementation of J.S.A.Kapp with deep modifications. #include #include #include #include #include typedef uint32_t word32; /* rotate functions */ #define ROTL(x,s) ((x)<<(s) | (x)>>(32-(s))) #define ROTR(x,s) ((x)>>(s) | (x)<<(32-(s))) /* Magic Contants */ #define P 0xb7e15163 #define Q 0x9e3779b9 #define ANDVAL 31 #define KR(x) (2*((x)+1)) #define MAX(x, y) (((x) > (y)) ? (x) : (y)) void RC5decrypt(word32 *in, int len, int b, word32 *key) { int i; int t; for(t = b << 2; len; len--) { key += t + 1; for (i = 0; i < t; i += 2) { in[1] -= *key--; in[1] = ROTR(in[1], in[0]&ANDVAL) ^ in[0]; in[0] -= *key--; in[0] ^= 0x63a72efb; in[0] = ROTR(in[0], in[1]&ANDVAL) ^ in[1]; } in[1] -= *key--; in[0] -= *key; in += 2; } } void RC5key(unsigned char *key, int b, word32 **ctx) { int t = (b << 2) + 2; int i; int x = ((b-1)/sizeof(word32))+1; int mix = 3 * (MAX(t,x)); word32 *L, *ky; word32 A = 0, B = 0; L = (word32 *) calloc((x+1), sizeof(word32)); memcpy((unsigned char *)L, key, b); ky = (word32 *) calloc((t+1), sizeof(word32)); *ky = P; /* Prep subkeys with magic Constants */ for(i = 1; i < t; i++) ky[i] = ky[i-1] + Q; for(i = 0; i < mix; i++) { A = ky[i%t] = ROTL((ky[i%t] + A + B), 3&ANDVAL); B = L[i%x] = ROTL((L[i%x] + A + B), ((A + B)&ANDVAL)); } free(L); *ctx = ky; } uif2iso-0.1.7a/src/blowfish.c0000644000175100017510000000772511070743130014761 0ustar margamarga/* Copyright (C) 2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ // modified by Luigi Auriemma for emulating the shameful customizations of MagicISO /* This code has been found on the website http://www.di-mgt.com.au/crypto.html The following is a small explanation from the website author: Here is Bruce Schneier's code in C for his Blowfish algorithm. This version is fully ANSI compliant and contains the "missing" P-box values omitted from the book. ... This code may be freely distributed. Updated 29 July 2003: thanks to Mehul Motani for pointing out an error in the code for readDataLine(). */ #include #include "blowfish.h" #include "bf_tab.h" #define N 16 #define noErr 0 #define DATAERROR -1 #define KEYBYTES 8 uint32_t F(blf_ctx *bc, uint32_t x) { uint32_t a; uint32_t b; uint32_t c; uint32_t d; uint32_t y; d = x & 0x00FF; x >>= 8; c = x & 0x00FF; x >>= 8; b = x & 0x00FF; x >>= 8; a = x & 0x00FF; y = bc->S[0][a] + bc->S[1][b]; y = y ^ bc->S[2][c]; y = y + bc->S[3][d]; return y ^ 0x28799a; } void Blowfish_encipher(blf_ctx *bc, uint32_t *xl, uint32_t *xr) { uint32_t Xl; uint32_t Xr; uint32_t temp; short i; Xl = *xl; Xr = *xr; for (i = 0; i < N; ++i) { Xl = Xl ^ bc->P[i]; Xr = F(bc, Xl) ^ Xr; Xr ^= 0x3fbe82a9; temp = Xl; Xl = Xr; Xr = temp; } temp = Xl; Xl = Xr; Xr = temp; Xr = Xr ^ bc->P[N]; Xl = Xl ^ bc->P[N + 1]; *xl = Xl; *xr = Xr; } void Blowfish_decipher(blf_ctx *bc, uint32_t *xl, uint32_t *xr) { uint32_t Xl; uint32_t Xr; uint32_t temp; short i; Xl = *xl; Xr = *xr; for (i = N + 1; i > 1; --i) { Xl = Xl ^ bc->P[i]; Xr = F(bc, Xl) ^ Xr; Xr ^= 0x3fbe82a9; /* Exchange Xl and Xr */ temp = Xl; Xl = Xr; Xr = temp; } /* Exchange Xl and Xr */ temp = Xl; Xl = Xr; Xr = temp; Xr = Xr ^ bc->P[1]; Xl = Xl ^ bc->P[0]; *xl = Xl; *xr = Xr; } short InitializeBlowfish(blf_ctx *bc, unsigned char key[], int keybytes) { short i; short j; short k; uint32_t data; uint32_t datal; uint32_t datar; /* initialise p & s-boxes without file read */ for (i = 0; i < N+2; i++) { bc->P[i] = 0; //bfp[i]; } for (i = 0; i < 256; i++) { bc->S[0][i] = ks0[i]; bc->S[1][i] = ks1[i]; bc->S[2][i] = ks2[i]; bc->S[3][i] = ks3[i]; } j = 0; for (i = 0; i < N + 2; ++i) { data = 0x00000000; for (k = 0; k < 4; ++k) { data = (data << 8) | (char)key[j]; j = j + 1; if (j >= keybytes) { j = 0; } } bc->P[i] = bc->P[i] ^ data; } datal = 0x00000000; datar = 0x00000000; for (i = 0; i < N + 2; i += 2) { Blowfish_encipher(bc, &datal, &datar); bc->P[i] = datal; bc->P[i + 1] = datar; } for (i = 0; i < 4; ++i) { for (j = 0; j < 256; j += 2) { Blowfish_encipher(bc, &datal, &datar); bc->S[i][j] = datal; bc->S[i][j + 1] = datar; } } return 0; } void blf_key (blf_ctx *c, unsigned char *k, int len) { InitializeBlowfish(c, k, len); } void blf_enc(blf_ctx *c, uint32_t *data, int blocks) { uint32_t *d; int i; d = data; for (i = 0; i < blocks; i++) { Blowfish_encipher(c, d, d+1); d += 2; } } void blf_dec(blf_ctx *c, uint32_t *data, int blocks) { uint32_t *d; int i; d = data; for (i = 0; i < blocks; i++) { Blowfish_decipher(c, d, d+1); d += 2; } } uif2iso-0.1.7a/src/dunno.c0000644000175100017510000000574611070705774014304 0ustar margamarga/* Copyright (C) 2007,2008 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl-2.0.txt */ #include static const uint8_t dunno_sbox[64] = { 0xa6,0xac,0xdb,0xb7,0xed,0x96,0x45,0x99,0x47,0xf7,0xe2,0x16,0xd8,0x69,0xa3,0x7e, 0x8f,0x58,0x58,0xee,0x1d,0xb5,0x39,0x13,0x23,0xf0,0x18,0xef,0xb0,0x0e,0x8b,0x3e, 0xc1,0x27,0xda,0x60,0xf3,0x94,0x62,0x40,0x6a,0xb6,0x34,0xce,0xaf,0x93,0x11,0x2a, 0x5d,0xf6,0x16,0x1e,0x33,0x5c,0x81,0x77,0x98,0xaf,0x1b,0x93,0xcc,0x91,0x60,0x32 }; void dunno_key(uint32_t *dunnoctx, char *key) { dunnoctx[0] = (key[0] << 11) | (key[1] << 3) | (key[2] >> 5); dunnoctx[1] = (key[2] << 17) | (key[3] << 9) | (key[4] << 1) | (key[5] >> 7); dunnoctx[2] = (key[5] << 15) | (key[6] << 8) | key[7]; dunnoctx[3] = dunnoctx[0]; dunnoctx[4] = dunnoctx[1]; dunnoctx[5] = dunnoctx[2]; } int dunno_decy(uint32_t x1, uint32_t x2, uint32_t x3) { if((((x1 >> 9) & 1) + ((x2 >> 11) & 1) + ((x3 >> 11) & 1)) <= 1) return(1); return(0); } uint32_t dunno_dec0(uint32_t x1, uint32_t x2) { uint32_t x; if(x2 ^ ((x1 >> 9) & 1)) { x = ((x1 >> 0x11) ^ (x1 >> 0x12) ^ (x1 >> 0x10) ^ (x1 >> 0x0d)); x1 = (x1 << 1) & 0x7ffff; if(x & 1) return(x1 ^ 1); } return(x1); } uint32_t dunno_dec1(uint32_t x1, uint32_t x2) { uint32_t x; if(x2 ^ ((x1 >> 11) & 1)) { x = ((x1 >> 0x14) ^ (x1 >> 0x15) ^ (x1 >> 0x10) ^ (x1 >> 0x0c)); x1 = (x1 << 1) & 0x3fffff; if(x & 1) return(x1 ^ 1); } return(x1); } uint32_t dunno_dec2(uint32_t x1, uint32_t x2) { uint32_t x; if(x2 ^ ((x1 >> 11) & 1)) { x = ((x1 >> 0x15) ^ (x1 >> 0x16) ^ (x1 >> 0x12) ^ (x1 >> 0x11)); x1 = (x1 << 1) & 0x7fffff; if(x & 1) return(x1 ^ 1); } return(x1); } uint32_t dunno_decx(uint32_t *dunnoctx) { uint32_t x; x = dunno_decy(dunnoctx[0], dunnoctx[1], dunnoctx[2]); dunnoctx[0] = dunno_dec0(dunnoctx[0], x); dunnoctx[1] = dunno_dec1(dunnoctx[1], x); dunnoctx[2] = dunno_dec2(dunnoctx[2], x); return((dunnoctx[0] ^ dunnoctx[1] ^ dunnoctx[2]) & 1); } void dunno_dec(uint32_t *dunnoctx, uint8_t *data, int datalen) { int i, j; uint8_t c; dunnoctx[0] = dunnoctx[3]; dunnoctx[1] = dunnoctx[4]; dunnoctx[2] = dunnoctx[5]; c = 0; for(i = 0; i < datalen; i++) { for(j = 0; j < 8; j++) { c = dunno_decx(dunnoctx) | (c << 1); } data[i] ^= c ^ dunno_sbox[i & 0x3f]; } } uif2iso-0.1.7a/COPYING0000644000175100017510000004310311070634120013230 0ustar margamarga GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. uif2iso-0.1.7a/uif2iso.txt0000644000175100017510000002141011104200170014303 0ustar margamarga###################################################################### Title: UIF2ISO Author: Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org UIF2ISO homepage: http://aluigi.org/mytoolz.htm#uif2iso ###################################################################### 1) Introduction 2) Shame on MagicISO and GPL violation 3) Usage on Windows 4) Usage on *nix/MacOSX 5) Features and known bugs 6) Technical info about the format 7) Comments about the UIF format ###################################################################### =============== 1) Introduction =============== UIF2ISO is an open source command-line/GUI tool for converting single and multipart UIF images to the original ISO format. It's released under the GNU GPL license and its source code is available in the src folder. The UIF image (Universal Image Format, although there is nothing of "universal" in it) in fact is just a compressed CD/DVD image created through a commercial program called MagicISO. ###################################################################### ====================================== 2) Shame on MagicISO and GPL violation ====================================== The chinese program called MagicISO has created the UIF format in the 2006 and, exactly like PowerISO already did at the beginning of that year, this format has been slowly started to be used to re-diffuse copyrighted material through BitTorrent... with the right effect that anyone hates this format (which is totally useless and, being closed, it must be NOT used on file sharing networks). This is a shameful marketing strategy made by the same author of MagicISO (a certain Gang JiaPing) for forcing the users who download these torrents to buy and use his program. These facts have been confirmed just recently due to the introduction of various senseless encryption mechanisms in the UIF files released on BitTorrent, all encryptions which have nothing to do with the UIF format but have been inserted only for trying to avoid the usage of my uif2iso alternative... without success 8-) The last fact is that the recent 5.5.272 version of MagicISO has introduced well "8" customized encryption algorithms plus other modifications JUST with the target of making the UIF format unreadable (again without success, look at uif2iso 0.1.6) and has also introduced support for the DAA image format. Unfortunately most of the code used by MagicISO has been "taken" from my other open source daa2iso tool violating my GPL license and showing how much ehmmmm "unprofessional" is the author of that program (the terms I used in a previous version of this file for describing him were most appropriate but not good for the neutrality of this readme): http://aluigi.org/misc/magiciso_gpl_violation.txt So, my best suggestion is to spread the voice about the shameful actions of MagicISO and its author and avoiding to download or keep the seeding of torrents of UIF or DAA images. And remember that uif2iso has been created only for supporting the UIF format and *NOT* for playing "cat and mouse" with an idiot who modifies this stupid zipped format each time for becoming the only program able to read it... ###################################################################### =================== 3) Usage on Windows =================== Using UIF2ISO on Windows is really a joke, just double click on UIF2ISO.exe and the tool will open a DOS-like window which contains all the needed informations about the status of conversion, then you will need to choose the input UIF file you want to convert and subsequently the name of the output file you want to create. Note that the correct extension (ISO, NRG or BIN/CUE) is automatically choosed by the tool depending by the input UIF file. If you want to use the tool from the command-line, so specifying the input and output files manually as in the older versions of the tool, you can do it too since UIF2ISO automatically recognizes if it has been launched from the console (cmd.exe) or through double-click. Just specify the input UIF file and the output ISO file you want to create like in the examples of the subsequent section. Remember that you can also associate the UIF extension to UIF2ISO, so when you will double-click on these files UIF2ISO will popup and will allow you to choose the output file immediately or you can also drag'n'drop the UIF file directly on UIF2ISO.EXE. Note that UIF2ISO is a stand-alone program, so all you need to have is just UIF2ISO.EXE and you can place it everywhere you want. ###################################################################### ======================= 4) Usage on *nix/MacOSX ======================= Compile the source code using 'make', this will generate the UIF2ISO executable. If you want to install it type 'make install' or just copy the executable where you want since it's the only file you need. The only requirement for compiling and using UIF2ISO is zlib (apt-get install zlib1g zlib1g-dev). Using it then it's simple, just specify the input file and the ISO file you want to create like the following example: uif2iso "my file.uif" output.iso ###################################################################### ========================== 5) Features and known bugs ========================== The tool supports password/encryption, little/big endian architectures and should work on many platforms (Windows, Linux, MacOS, *BSD, Amiga and others). The magiciso_is_shit function needed for the strange UIF files released from August 2008 does NOT work on big endian architectures (like PowerPC) due to the usage of various encryption algorithms which break this compatibility. The NRG file (compressed UIF) created by MagicISO is invalid so, although my tool tries to fix some fields and generates an additional CUE file, is possible that the resulted image isn't fully recognized by the burning/mounting program you want to use. During my tests I have found (only one time) also an invalid output ISO file (the uif was decompressed with both uif2iso and MagicISO) which was possible to read correctly only through MagicISO... it's useless to say that is a shame since creating non-standard images is an INTENTIONAL action made by the MagicISO's programmer!!! A known micro-bug is that on Windows 95/98/ME works only the so called GUI version because the method I use to know if the program has been launched from the console or through double-click is not compatible with this OS, anyway this is not a problem since the 99% of the Windows users don't like the command-line 8-) I'm available for any comment or feedback, so if you find a compatibility problem with a specific UIF image (and you are sure that the image is perfect) send me a mail. ###################################################################### ================================== 6) Technical info about the format ================================== UIF2ISO is open source so there is nothing better than its source code for explaining in detail this file format. In short UIF is a compressed disk image which can be derived by 3 types of input images: - ISO: only the classical data - BIN/CUE: data, audio or mixed content the UIF file contains a BLMS section with raw CUE informations (UIF2ISO uses them to generate the relative CUE file) and a BLSS field containing the original CUE file used by who created the UIF - NRG: disk image in Nero v2 format unfortunately for some reasons which I don't know the "UIFed" NRG image generated by MagicISO is invalid (these images don't work with other programs included Nero which is the creator of the NRG format!) and although my UIF2ISO fixes some of these fields is still possible that with some type of images the fixed NRG could not work since not 100% compatible. Another work-around I have adopted is the generation of an additional CUE file derived from the NRG one which in my test worked perfectly with data, audio and mixed CDs and partially with CD extra. ###################################################################### ================================ 7) Comments about the UIF format ================================ I don't like and don't approve the UIF format because it's proprietary and doesn't give benefits. What you can do with UIF can be done better with ZIP or 7zip without the need to be forced to buy a software like MagicISO only for burning or converting a CD/DVD image. Ok exists my tool which can do the job but this is not a valid reason to continue to use this useless format. So if you want to create a CD/DVD image, DO NOT USE UIF! ###################################################################### uif2iso-0.1.7a/uif2iso.exe0000644000175100017510000026200011104356500014260 0ustar margamargaMZ@ !L!This program cannot be run in DOS mode. $PEL>I 8`&00@ S Lp .text`P`.data0@`.rdata`2@4@`@.bss %@.idataLP@0.rsrcp V@0U A]t&U A]t&US$$P@e EED$0AD$A$AD$ ED$AuJ0A;D$AD$A$ %$|A0AD$C$AD$C0$AD$CP$qot&U$hA&U$hA&USE=w;=rKD$$1[]=tY=t=u=t&tE=uD$$tst$vи럍&1jD$$ mtSn$ и\t&$иfCD$$%D$$ D$$۸I Uh@A tih@APZYthAhqAЃ0At5 h%@A t.h2@APxZYt h0AЃÍv렐ېUh@A8 t%hF@AP+ZYt hqAЃf䐐U1҉M%NA0A1NA1ABu͸0APA]Í&ṲAS]щ % ыSЉ  % ыSЉK % ыS ЉK %  щK []Í&ṲAҋEtf]Ív'U ̤AS]t'щ % щ []Ðt&UWVS̤AEp8 1 Éщ1 É %1 É%1 É% E H[^_]fUS̤A]щ % ыS  % ыSK % ыSKfCfC fC fC % ыSK % эCKPdX̤Au ]Ðt&S$щ % ыS n. N `Qq1  a! A Y ;y9 i)  I U+u5  e% E ] S}= m-  M S#s3  c# C [ C{; k+  K W@3w7 g' G  _ c? o/ O `Psp0  ` @ X ;x8 h( H T+t4  d$ D \ S|< l,  L R#r2  b" B Z Cz: j*  J V@3v6 f& F  ^ c~> n. N `Qq1  a! A Y ;y9 i)  I U+u5  e% E ] S}= m-  M S#s3  c# C [ C{; k+  K W@3w7 g' G  _ c? o/ O A@!  @a`10  @incorrect header checkunknown compression methodinvalid window sizeunknown header flags setheader crc mismatchinvalid block typeinvalid stored block lengthstoo many length or distance symbolsinvalid code lengths setinvalid literal/lengths setinvalid distances setinvalid literal/length codeinvalid distance codeinvalid distance too far backinvalid bit length repeatincorrect data checkincorrect length checkt&'UWVS|$t.$ht P tVpt$(tt&|[^_]ÍvE L$pt$($T$lM8t$h{D$Xui$1Ĝ[^_]ÐT$Hf|Tpu BT$HvL$H9L$@sL$@Ltp)xFv~$t|$DtfD$RltPDtpfltRFvD$L9\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]1kfE9s鐋]K1RUWVSMEƋEωM] u9v$ȉ1҃[^_f9v(ȉڃ[^_Åu 1Ɖ1EЃUu9M)ÉME븉ŠM +EEM ЉEME܉M ЉuU׉9Ur u9Er})}U؋M)ˊMЊM ؊M7v;ubgUWVS4u}EU xEΉ]ĉljẺӋUąu9v=UE 9]vkE]Eȅt ]U]EU4[^_fu 1Ɖ1E؃EzكjfEăEu$9]U)]ĉŰM̉M]mfUĊM +EԉEЉM ЉE؊Mu܉M Љu؉׉EӉ9r u9rf+M]؉)ډMӊM ؊MEU;M_O,D$<\$\$4t$ t$8l$(l$0|$$tpt4uU\$|$t$|$,$‰Ћ\$t$ |$$l$(,É,$|$ E$H։\$t$=볍|$|$,$Pu\$t$낐%\A%A%dA%ܱA%`A%lA%A%A%pA%رA%A%A%A%A%A%A%A%A%A%A%ԱA%A%ȱA%A%A%̱A%A%бA%A%A%ıA%A%xA%tA%A%A%A%PA%DA%HA%LAUvU%A%A@P@     w{qA @%Alibgcc_s_1.dll__register_frame_infolibgcj_s.dll_Jv_RegisterClasses__deregister_frame_info Press RETURN to quit Error Error: the compressed input is wrong or incomplete Error: the magiciso_is_shit encryption can't work on your system Error: the input lzma block is too short (%u) Error: the compressed LZMA input is wrong or incomplete (%d) Error: problems during the writing of the output file Error: incomplete input file, can't read %u bytes - set DES encryption key: %.32s - DES password: %02x %02x %02x %02x %02x %02x %02x %02x - BIN name stored in the UIF file: %s - CUE name stored in the UIF file: %s FILE "%s" BINARY TRACK %02d AUDIO TRACK %02d MODE%d/%d INDEX %02d %02d:%02d:%02d - create %s rb- the output file already exists, do you want to overwrite it (y/N)? wb- open %s - Alert: wrong NRG header offsetNER5NERODAOXDAOI- correcting last DAO index2SINF- correcting SINF to %u tracks %02d:%02d:%02d- generate a new CUE file derived from the NRG one_nrg.cue TRACK %02d MODE2/%u TRACK %02d MODE1/%u INDEX 00 00:00:00 INDEX 00 %s INDEX 01 %s ETN2ETNFCDTX.cdtCDTEXTFILE "%s" r+b- found NRG end of file at offset 0x%08x%08x Error: the truncated file is smaller than how much I requested is possible that ftruncate() doesn't support large files Please contact me reporting also the sizeo of the UIF and your platform- Alert: seems that the file has not been truncated to the correct NRG sizeChoose the name of the output file to create (the extension is automatic)- %s Select the input UIF file to convert UIF2ISO 0.1.7 by Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org Usage: %s The output ISO,CUE/BIN,MDS/MDS,CCD,NRG extension is choosed by this tool an error here means that your exe has no full LARGE_FILES 64 bit support! Error: wrong bbis signature (%08x) file size %08x%08x version %hu image type %hu padding %hu sectors %u sectors size %u blhr offset %08x%08x blhr size %u hash %s others %08x %08x %02x %02x %02x %02x %08x - disable any encryption- enable magiciso_is_shit encryption- enable fixedkey encryption- the input file is protected by password, insert it: - Alert: the size of the bbis struct and the one specified by bsdr don't match Error: wrong blhr signature (%08x) 1.2.3 Error: zlib initialization error- raw or mixed type image- Alert: wrong blms signature (%08x) - Alert: wrong blss signature (%08x) - Alert: this type of image (%hu) is not supported by this tool, I try as ISO - ISO output image format.iso- BIN/CUE output image format.bin- MDS output image format.mdf- CCD (CloneCD) output image format.img- NRG (Nero v2) output image format.nrg Error: the output image %u is not supported by this tool, contact me - generate an "experimental" CUE file for more compatibility on various systems_uif2iso.cue.cue.mds.ccd.sub- start unpacking: %03d%% Error: input size is bigger than output Error: unknown type (%d) 100%% - 0x%08x%08x bytes written Please keep in mind that MagicISO creates INVALID NRG files which not only are unreadable by the various burners/mounters/converters for this type of image but also by the same Nero which owns the original NRG format, so if the output NRG file doesn't work is enough "normal". This is the reason why this tool will create an additional CUE file which can be used in case the NRG one doesn't work. If you are trying to mount the CUE file but it gives errors or you see no data try to enable all the emulation options of your mounting program and it will work perfectly. - finishedD@C@C@C@C@0123456789abcdefimage file*.iso;*.cue;*.bin;*.mds;*.mdf;*.ccd;*.img;*.sub;*.nrg(*.*)*.*UIF file*.uif(*.*)*.*FAngS)snOt32AglEy29TarsI;bum87OrYx*THeCaARMy67sabot&FoOTs:blaZe70panIc+elD%self79Usnea*hest98apex(TUft!BLOKE70sword18rEpP}ARb10naVY=RousePAIR18gAG:swAYsgums}Box73yANgnaVal45drain]Cams42hEt83faiLs)rIaNt$Notch5ExaCT&art*MEteS47jOAwOAOAOAOAOAOAOAOAOAOA PAPA*PA3b $;" r(-Exb}doITH}'>AcG t.no:7`L knU{7,gm;e' )̒9 i{f} ϑ^و/$[Qy{;v.97yY̗&-1.Bh;+jLu.x7BjQ满PcKkؽ%=YBD n *Ngd_ڈ鿾dW{x`M``FѰ8Ew63kBqA_^;Z4ٷ,Q+:Ֆ}}>(-}|%rZLZq)GW;()f(.y_xU`uD^mm%adâW<'*:m?!cf&(3uU4V<wQ( gQ̫_QM08bX7 z{>d!Q2Ow~㶨F=)iSHd$m-if! FEdlX [@X̻k~jEY:D 5>ʹrdfGof,ҏ"W##v215VbuZ6ns҈bIPLVq z2E{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @@@ @ @@ @@ @@@ @@ @@@ @@@@ @ @ @@@@ @@@@@ @ @ @@@@ @@ @@ @ @@ @@@ @@@@ @ @@ @@@@@ @@ @@                                                             B@@@BB@@@@BBB@BBB@B@@B@BBBB@B@@@ 1Ѭߘr/Ḗ~&jE|,G$l iciNWqX~=t XrX͋qJT{YZ90`*#`(yA8۸y:`l>w'K1/x`\`U%U攫UbHW@cj9U*4\̴ATr|*oc]ũ+1t>\3֯\$lS2zw(H;Kkē!(f a!`|H2]]]u#&܈e>#Ŭom9BD . Ji^Bh!la gӫҠQjh/T(3Ql n;zP;*~ev9>YfCoEå}^;uos D@jVbNw?6r=B$7H ۛIrS{y%P;LylO`@ž\^c$johSl>9oR;Qm,0DE ^J3(fK.WtE9_ ӹyU 2`yr,@%g̣饎"2u<kaP/R=2`#H{1S>W\o.ViB~(2gsUO'[iXʻ]=!lJ[-ySeEIҐK3~ˤAb Lw6~д+MەqՓkю%ǯ/[{AI~-%^q h"W6d$ cUYCxSZ٢[} Źv&ϕbhAJsN-GJ{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'`b@j4ί*]3\w̑`2                              LOKI91 library v3.0, Copyright (C) 1991 Lawrence Brown & UNSW| A AB F| !AAB F|  "AAB FhhD\$(4<*>Pn~²̲޲",6>FPX`jt~³ֳ̳0D*>Pn~²̲޲",6>FPX`jt~³ֳ̳0DExitProcessQGetModuleHandleAlGetProcAddressSetUnhandledExceptionFilter'__getmainargs<__p__environ>__p__fmodeP__set_app_typey_cexit_chsize_errno_filelengthi64_iob^_onexit_setmodeatexit!calloc*exit-fclose0fflush2fgetpos3fgets8fopen9fprintf>fread?freeDfsetposGfwritermallocxmemcpyzmemset}perrorprintfputsreallocsetbufsignalsprintfstrcpystrlenstrncpystrrchrtoupperGetForegroundWindowTGetWindowLongA GetOpenFileNameA GetSaveFileNameAKERNEL32.dllmsvcrt.dll((USER32.dll<<COMDLG32.DLL>I P>I8>I >Ih>I IDD_ICON \( @