File: daa_crypt.h

package info (click to toggle)
daa2iso 0.1.7e-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, squeeze, stretch, wheezy
  • size: 168 kB
  • ctags: 338
  • sloc: ansic: 2,356; makefile: 37
file content (169 lines) | stat: -rw-r--r-- 3,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
    Copyright 2007,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.

    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

    http://www.gnu.org/licenses/gpl-2.0.txt
*/



static u8   daa_crypt_table[128][256];



void daa_crypt_key(u8 *pass, int num) {    // 00453360
    int     a,
            b,
            c,
            d,
            s,
            i,
            p,
            passlen;
    short   tmp[256];
    u8      *tab;

    passlen = strlen(pass);
    tab = daa_crypt_table[num - 1];
    d = num << 1;

    for(i = 0; i < 256; i++) {
        tmp[i] = i;
    }
    memset(tab, 0, 256);

    if(d <= 64) {
        a = pass[0] >> 5;
        if(a >= d) a = d - 1;
        for(c = 0; c < d; c++) {
            for(s = 0; s != 11;) {
                a++;
                if(a == d) a = 0;
                if(tmp[a] != -1) s++;
            }
            tab[c] = a;
            tmp[a] = -1;
        }
        return;
    }
    a = pass[0];
    b = d - 32;
    a >>= 5;
    tmp[a + 32] = -1;
    tab[0] = a + 32;
    p = 1;
    for(s = 1; s < b; s++) {
        c = 11;
        if(p < passlen) {
            c = pass[p];
            p++;
            if(!c) c = 11;
        }
        for(i = 0; i != c;) {
            a++;
            if(a == d) a = 32;
            if(tmp[a] != -1) i++;
        }
        tmp[a] = -1;
        tab[s] = a;
    }
    i = pass[0] & 7;
    if(!i) i = 7;
    for(; s < d; s++) {
        for(c = 0; c != i;) {
            a++;
            if(a == d) a = 0;
            if(tmp[a] != -1) c++;
        }
        tmp[a] = -1;
        tab[s] = a;
    }
    for(i = 0; i < d; i++) {
        tmp[i] = tab[i];
    }
    i = pass[0] & 24;
    if(i) {
        a = 0;
        for(s = 0; s < d; s++) {
            for(c = 0; c != i;) {
                a++;
                if(a == d) a = 0;
                if(tmp[a] != -1) c++;
            }
            c = tmp[a];
            tmp[a] = -1;
            tab[s] = c;
        }
    }
}



void daa_crypt_block(u8 *ret, u8 *data, int size) { // 00453540
    int     i;
    u8      c,
            t,
            *tab;

    if(!size) return;
    tab = daa_crypt_table[size - 1];

    memset(ret, 0, size);
    for(i = 0; i < size; i++) {
        c = data[i] & 15;
        t = tab[i << 1];
        if(t & 1) c <<= 4;
        ret[t >> 1] |= c;

        c = data[i] >> 4;
        t = tab[(i << 1) + 1];
        if(t & 1) c <<= 4;
        ret[t >> 1] |= c;
    }
}



void daa_crypt(u8 *data, int size) {
    int     blocks,
            rem;
    u8      tmp[128],
            *p;

    blocks = size >> 7;
    for(p = data; blocks--; p += 128) {
        daa_crypt_block(tmp, p, 128);
        memcpy(p, tmp, 128);
    }

    rem = size & 127;
    if(rem) {
        daa_crypt_block(tmp, p, rem);
        memcpy(p, tmp, rem);
    }
}



void daa_crypt_init(u8 *pwdkey, u8 *pass, u8 *daakey) {
    int     i;

    for(i = 1; i <= 128; i++) {
        daa_crypt_key(pass, i);
    }
    daa_crypt_block(pwdkey, daakey, 128);
}