oracle_ebs_authentication 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,100 +1,49 @@
1
- # The Java original source code was taken form http://www.milci.com/eappsjira
2
- # Original Java source is included in comments followed by corresponding Ruby code.
3
- # As original Java source is not documented then Ruby source code was done
4
- # as similar as possible to Java code to avoid differences in functionality.
5
- #
6
- # http://code.google.com/p/jebusinessauth/source/browse/trunk/src/com/milci/ebusinesssuite/eBusinessSuiteSecurity.java
7
- #
8
-
9
1
  require "digest/sha1"
10
2
 
11
3
  module OracleEbsAuthentication
12
-
13
- # public class eBusinessSuiteSecurity {
4
+ # The Java original source code was taken form
5
+ # http://code.google.com/p/jebusinessauth/source/browse/trunk/src/com/milci/ebusinesssuite/eBusinessSuiteSecurity.java
6
+ #
7
+ # As original Java source is not documented then Ruby source code was done
8
+ # as similar as possible to Java code to avoid differences in functionality.
9
+ #
14
10
  class Security
15
-
16
- # public eBusinessSuiteSecurity() {
17
- # }
18
11
  def initialize
19
12
  end
20
13
 
21
- # static String control(String s1, int i1, String s2) {
22
- # return newControl(s1, s2, i1, 0);
23
- # }
24
14
  def control(s1, i1, s2)
25
15
  return new_control(s1, s2, i1, 0)
26
16
  end
27
17
 
28
- #private static int[] a(byte abyte0[], int i1) {
29
18
  def a(abyte0, i1)
30
- # int ai[] = new int[16];
31
19
  ai = [nil]*16
32
- # int ai1[] = new int[5];
33
20
  ai1 = [nil]*5
34
- # u(ai1, null);
35
21
  u(ai1, nil)
36
- # int l1 = ai.length;
37
22
  l1 = ai.length
38
- # int k1 = 0;
39
23
  k1 = 0
40
- # int j2 = 0;
41
24
  j2 = 0
42
- # int j1;
43
- # for (j1 = 0; j1 < (i1 & -4); j1 += 4) {
44
25
  j1 = 0
45
26
  while j1 < (i1 & -4)
46
- # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
47
- # abyte0[j2 + 3] << 24;
48
27
  ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
49
28
  abyte0[j2 + 3] << 24) & 0xffffffff
50
- # if (++k1 == l1) {
51
- # u(ai1, ai);
52
- # k1 = 0;
53
- # }
54
29
  k1 +=1
55
30
  if (k1 == l1)
56
31
  u(ai1, ai)
57
32
  k1 = 0
58
33
  end
59
- # j2 += 4;
60
34
  j2 += 4
61
- # }
62
35
  j1 += 4
63
36
  end
64
- #
65
- # j1 = i1 - j1;
66
37
  j1 = i1 - j1
67
- # if (j1 == 1) {
68
- # ai[k1] = abyte0[j2] & 0xff | 0x8000;
69
- # }
70
38
  if (j1 == 1)
71
39
  ai[k1] = abyte0[j2] & 0xff | 0x8000
72
- # else
73
- # if (j1 == 2) {
74
- # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000;
75
- # }
76
40
  elsif (j1 == 2)
77
41
  ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000) & 0xffffffff
78
- # else
79
- # if (j1 == 3) {
80
- # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
81
- # 0x80000000;
82
- # }
83
42
  elsif (j1 == 3)
84
43
  ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 | 0x80000000) & 0xffffffff
85
- # else {
86
- # ai[k1] = 128;
87
- # }
88
44
  else
89
45
  ai[k1] = 128
90
46
  end
91
- # if (++k1 >= l1 - 2) {
92
- # while (k1 < l1) {
93
- # ai[k1++] = 0;
94
- # }
95
- # u(ai1, ai);
96
- # k1 = 0;
97
- # }
98
47
  k1 += 1
99
48
  if (k1 >= l1 - 2)
100
49
  while (k1 < l1)
@@ -104,128 +53,62 @@ module OracleEbsAuthentication
104
53
  u(ai1,ai)
105
54
  k1 = 0
106
55
  end
107
- # while (k1 < l1 - 2) {
108
- # ai[k1++] = 0;
109
- # }
110
56
  while (k1 < l1 - 2)
111
57
  ai[k1] = 0
112
58
  k1 += 1
113
59
  end
114
- # int i2 = i1;
115
60
  i2 = i1
116
- # ai[k1++] = i2 >> 29 & 7;
117
61
  ai[k1] = i2 >> 29 & 7
118
62
  k1 += 1
119
- # ai[k1] = i2 << 3;
120
63
  ai[k1] = (i2 << 3) & 0xffffffff
121
- # u(ai1, ai);
122
64
  u(ai1, ai)
123
- # return ai1;
124
65
  return ai1
125
- #}
126
66
  end
127
67
 
128
-
129
- # static String newCheck(String s1, String s2, boolean flag) {
130
68
  def new_check(s1, s2, flag)
131
- # if (s1 == null || s2 == null ||
132
- # s2.length() >= "ZG_ENCRYPT_FAILED_".length() &&
133
- # s2.substring(0,
134
- # "ZG_ENCRYPT_FAILED_".length()).equals("ZG_ENCRYPT_FAILED_")) {
135
- # return null;
136
- # }
137
69
  if (s1 == nil || s2 == nil ||
138
70
  s2.length >= "ZG_ENCRYPT_FAILED_".length &&
139
71
  s2[0, "ZG_ENCRYPT_FAILED_".length] == "ZG_ENCRYPT_FAILED_")
140
72
  return nil
141
73
  end
142
- # byte abyte0[];
143
- # try {
144
- # abyte0 = s1.getBytes("UTF8");
145
- # }
146
- # catch (UnsupportedEncodingException _ex) {
147
- # return null;
148
- # }
149
74
  abyte0 = s1.dup
150
- # int l2 = abyte0.length;
151
75
  l2 = abyte0.length
152
- # int i3 = s2.length();
153
76
  i3 = s2.length
154
- # int i1 = 1;
155
77
  i1 = 1
156
- # byte byte0 = 2;
157
78
  byte0 = 2
158
- # int j1 = i3 - 2 - i1 * 2;
159
79
  j1 = i3 - 2 - i1 * 2
160
- # if (j1 <= 0) {
161
- # return null;
162
- # }
163
80
  if (j1 <= 0)
164
81
  return nil
165
82
  end
166
- # int k1 = (j1 / 16) * 8;
167
83
  k1 = (j1 / 16) * 8
168
- # if (k1 <= 0) {
169
- # return null;
170
- # }
171
84
  if (k1 <= 0)
172
85
  return nil
173
86
  end
174
- # int l1 = (j1 % 16) / 2;
175
87
  l1 = (j1 % 16) / 2
176
- # int i2 = l1 + i1;
177
88
  i2 = l1 + i1
178
- # int j2 = k1 - 1 - byte0;
179
89
  j2 = k1 - 1 - byte0
180
- # if (j2 <= 0) {
181
- # return null;
182
- # }
183
90
  if (j2 <= 0)
184
91
  return nil
185
92
  end
186
- # if (!s2.substring(0, 2).equals("ZG")) {
187
- # return null;
188
- # }
189
93
  if (not s2[0, 2] == "ZG")
190
94
  return nil
191
95
  end
192
- # String s3 = s2.substring(2);
193
96
  s3 = s2[2..-1]
194
- # byte abyte1[] = p(s3);
195
97
  abyte1 = p(s3)
196
- # byte abyte2[] = new byte[abyte1.length - i2];
197
98
  abyte2 = "\0"*(abyte1.length - i2)
198
- # byte abyte3[] = new byte[i2];
199
99
  abyte3 = "\0"*i2
200
- # System.arraycopy(abyte1, 0, abyte2, 0, abyte1.length - i2);
201
100
  abyte2[0, abyte1.length - i2] = abyte1[0, abyte1.length - i2]
202
- # System.arraycopy(abyte1, abyte1.length - i2, abyte3, 0, i2);
203
101
  abyte3[0, i2] = abyte1[abyte1.length - i2, i2]
204
- # byte abyte4[] = new byte[i2 + l2];
205
102
  abyte4 = "\0"*(i2 + l2)
206
- # System.arraycopy(abyte3, 0, abyte4, 0, i2);
207
103
  abyte4[0, i2] = abyte3[0, i2]
208
- # System.arraycopy(abyte0, 0, abyte4, i2, l2);
209
104
  abyte4[i2, l2] = abyte0[0, l2]
210
- # byte abyte5[] = v(null, abyte4, abyte2);
211
105
  # puts "<br/>DEBUG new_check: abyte4=#{abyte4.inspect} abyte2=#{abyte2.unpack("H*")[0]}"
212
106
  abyte5 = v(nil, abyte4, abyte2)
213
- # if (abyte5 == null) {
214
- # return null;
215
- # }
216
107
  if (abyte5 == nil)
217
108
  # puts "<br/>DEBUG new_check: :nil6"
218
109
  return nil
219
110
  end
220
- # int j3 = abyte5.length;
221
111
  j3 = abyte5.length
222
- # for (int k2 = byte0; k2 < abyte5.length; k2++) {
223
- # if (abyte5[k2] != 0) {
224
- # continue;
225
- # }
226
- # j3 = k2;
227
- # break;
228
- # }
229
112
  for k2 in byte0...abyte5.length
230
113
  if (abyte5[k2] != 0)
231
114
  next
@@ -233,48 +116,21 @@ module OracleEbsAuthentication
233
116
  j3 = k2
234
117
  break
235
118
  end
236
- #
237
- # byte abyte6[] = new byte[j3 - byte0];
238
119
  abyte6 = "\0"*(j3 - byte0)
239
- # System.arraycopy(abyte5, byte0, abyte6, 0, j3 - byte0);
240
120
  abyte6[0, j3 - byte0] = abyte5[byte0, j3 - byte0]
241
- # String s4;
242
- # try {
243
- # s4 = new String(abyte6, "UTF8");
244
- # }
245
- # catch (UnsupportedEncodingException _ex) {
246
- # return null;
247
- # }
248
121
  s4 = abyte6
249
- # if (s4 != null && flag) {
250
- # return w(s4, 0, flag);
251
- # }
252
122
  if (s4 != nil && flag)
253
123
  return w(s4, 0, flag)
254
- # else {
255
- # return s4;
256
- # }
257
124
  else
258
125
  return s4
259
126
  end
260
- # }
261
127
  end
262
128
 
263
- # private static void c(int ai[]) {
264
- # ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc;
265
- # ai[2] = j(ai[1], 30);
266
- # }
267
129
  def c(ai)
268
130
  ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc
269
131
  ai[2] = j(ai[1], 30)
270
132
  end
271
133
 
272
- # private static void d(byte abyte0[], int ai[]) {
273
- # int ai1[] = new int[2];
274
- # t(abyte0, ai1);
275
- # F(ai1, ai);
276
- # x(ai1, abyte0);
277
- # }
278
134
  def d(abyte0, ai)
279
135
  ai1 = [nil]*2
280
136
  t(abyte0, ai1)
@@ -288,22 +144,6 @@ module OracleEbsAuthentication
288
144
  # puts "<br/>DEBUG d: after x abyte0=#{abyte0.unpack("H*")[0]}"
289
145
  end
290
146
 
291
- # private static byte[] e(int ai[]) {
292
- # byte abyte0[] = new byte[4];
293
- # byte abyte1[] = null;
294
- # if (ai != null) {
295
- # abyte1 = new byte[ai.length];
296
- # for (int i1 = 0; i1 < ai.length; i1++) {
297
- # abyte0[3] = (byte) (ai[i1] & 0xff);
298
- # abyte0[2] = (byte) ( (ai[i1] & 0xff00) >> 8);
299
- # abyte0[1] = (byte) ( (ai[i1] & 0xff0000) >> 16);
300
- # abyte0[0] = (byte) ( (ai[i1] & 0xff000000) >> 24);
301
- # abyte1[i1] = (byte) (abyte0[0] ^ abyte0[1] ^ abyte0[2] ^ abyte0[3]);
302
- # }
303
- #
304
- # }
305
- # return abyte1;
306
- # }
307
147
  def e(ai)
308
148
  abyte0 = "\0"*4
309
149
  abyte1 = nil
@@ -320,17 +160,6 @@ module OracleEbsAuthentication
320
160
  return abyte1
321
161
  end
322
162
 
323
- # private static byte f(int i1) {
324
- # byte byte0 = 0;
325
- # int j1 = (char) i1 & 0x40;
326
- # if (j1 >= 1) {
327
- # byte0 = (byte) ( (char) i1 - 55);
328
- # }
329
- # else {
330
- # byte0 = (byte) ( (char) i1 & 0xf);
331
- # }
332
- # return byte0;
333
- # }
334
163
  def f(i1)
335
164
  byte0 = 0
336
165
  j1 = i1 & 0x40
@@ -342,137 +171,73 @@ module OracleEbsAuthentication
342
171
  return byte0
343
172
  end
344
173
 
345
- # private static byte[] g(byte abyte0[], byte abyte1[]) {
346
174
  def g(abyte0, abyte1)
347
- # if (abyte0.length < 32) {
348
- # return null;
349
- # }
350
175
  if (abyte0.length < 32)
351
176
  # puts "<br/>DEBUG g: nil1"
352
177
  return nil
353
178
  end
354
- # if (abyte1.length % 8 != 0) {
355
- # return null;
356
- # }
357
179
  if (abyte1.length % 8 != 0)
358
180
  # puts "<br/>DEBUG g: nil2"
359
181
  return nil
360
182
  end
361
- # int i1 = abyte1.length / 8;
362
183
  i1 = abyte1.length / 8
363
- # byte abyte3[] = new byte[8];
364
184
  abyte3 = "\0"*8
365
- # byte abyte4[] = new byte[8];
366
185
  abyte4 = "\0"*8
367
- # byte abyte5[] = new byte[8];
368
186
  abyte5 = "\0"*8
369
- # byte abyte2[] = new byte[8];
370
187
  abyte2 = "\0"*8
371
- # System.arraycopy(abyte0, 0, abyte3, 0, 8);
372
188
  abyte3[0,8] = abyte0[0, 8]
373
- # System.arraycopy(abyte0, 8, abyte4, 0, 8);
374
189
  abyte4[0,8] = abyte0[8, 8]
375
- # System.arraycopy(abyte0, 16, abyte5, 0, 8);
376
190
  abyte5[0,8] = abyte0[16, 8]
377
- # System.arraycopy(abyte0, 24, abyte2, 0, 8);
378
191
  abyte2[0,8] = abyte0[24, 8]
379
- # int ai[] = l(abyte3, false);
380
192
  ai = l(abyte3, false)
381
- # int ai1[] = l(abyte4, true);
382
193
  ai1 = l(abyte4, true)
383
- # int ai2[] = l(abyte5, false);
384
194
  ai2 = l(abyte5, false)
385
- # byte abyte6[] = new byte[abyte1.length];
386
195
  abyte6 = "\0"*(abyte1.length)
387
- # int j1 = 0;
388
196
  j1 = 0
389
- # for (int k1 = 0; j1 < i1; k1 += 8) {
390
197
  k1 = 0
391
198
  while (j1 < i1)
392
- # q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false);
393
199
  q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false)
394
200
  # puts "<br/>DEBUG g: after q() abyte6=#{abyte6.unpack("H*")[0]}"
395
- # j1++;
396
201
  j1 += 1
397
- # }
398
202
  k1 += 8
399
203
  end
400
- #
401
- # byte byte0 = abyte6[abyte1.length - 1];
402
204
  byte0 = abyte6[abyte1.length - 1]
403
205
  # puts "<br/>DEBUG g: abyte1=#{abyte1.unpack("H*")[0]}"
404
206
  # puts "<br/>DEBUG g: abyte1.length=#{abyte1.length}"
405
207
  # puts "<br/>DEBUG g: abyte6=#{abyte6.unpack("H*")[0]}"
406
- # if (byte0 < 1 || byte0 > 8) {
407
- # return null;
408
- # }
409
208
  if (byte0 < 1 || byte0 > 8)
410
209
  # puts "<br/>DEBUG g: nil3"
411
210
  # puts "<br/>DEBUG g: byte0=#{byte0}"
412
211
  return nil
413
212
  end
414
- # for (int l1 = abyte1.length - byte0; l1 < abyte1.length; l1++) {
415
213
  for l1 in (abyte1.length-byte0)...abyte1.length
416
- # if (abyte6[l1] != byte0) {
417
- # return null;
418
- # }
419
214
  if (abyte6[l1] != byte0)
420
215
  # puts "<br/>DEBUG g: nil4"
421
216
  return nil
422
217
  end
423
- # }
424
218
  end
425
- #
426
- # byte abyte7[] = new byte[abyte1.length - byte0];
427
219
  abyte7 = "\0"*(abyte1.length - byte0)
428
- # System.arraycopy(abyte6, 0, abyte7, 0, abyte1.length - byte0);
429
220
  abyte7[0, abyte1.length - byte0] = abyte6[0, abyte1.length - byte0]
430
- # return abyte7;
431
221
  # puts "<br/>DEBUG g: abyte7=#{abyte7.unpack("H*")[0]}"
432
222
  return abyte7
433
- # }
434
223
  end
435
224
 
436
- # private static void h(int ai[]) {
437
- # ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6;
438
- # ai[2] = j(ai[1], 30);
439
- # }
440
225
  def h(ai)
441
226
  ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6
442
227
  ai[2] = j(ai[1], 30)
443
228
  end
444
229
 
445
- # private static byte[] i(byte abyte0[], byte abyte1[], byte abyte2[]) {
446
- # return G(y(abyte0, abyte1), abyte2);
447
- # }
448
230
  def i(abyte0, abyte1, abyte2)
449
231
  return g_(y(abyte0, abyte1), abyte2)
450
232
  end
451
233
 
452
- # private static int j(int i1, int j1) {
453
- # return i1 << j1 | i1 >>> 32 - j1;
454
- # }
455
- # TODO: check impact of >>> substitution with >>
456
234
  def j(i1, j1)
457
235
  return (i1 << j1 | i1 >> 32 - j1) & 0xffffffff
458
236
  end
459
237
 
460
- # private static byte[] k(byte abyte0[], byte abyte1[], int i1) {
461
238
  def k(abyte0, abyte1, i1)
462
- # if (abyte0 == null || abyte1 == null) {
463
- # return null;
464
- # }
465
239
  if (abyte0 == nil || abyte1 == nil)
466
240
  return nil
467
- # else {
468
- # int ai[] = a(abyte0, abyte0.length);
469
- # byte abyte2[] = e(ai);
470
- # byte abyte3[] = new byte[258];
471
- # B(abyte3, abyte2, null, 5);
472
- # byte abyte4[] = new byte[i1];
473
- # B(abyte3, abyte1, abyte4, i1);
474
- # return abyte4;
475
- # }
476
241
  else
477
242
  ai = a(abyte0, abyte0.length)
478
243
  abyte2 = e(ai)
@@ -482,194 +247,94 @@ module OracleEbsAuthentication
482
247
  b_(abyte3, abyte1, abyte4, i1)
483
248
  return abyte4
484
249
  end
485
- # }
486
250
  end
487
251
 
488
- # private static int[] l(byte abyte0[], boolean flag) {
489
252
  def l(abyte0, flag)
490
- # byte abyte1[] = new byte[56];
491
253
  abyte1 = "\0"*56
492
- # byte abyte2[] = new byte[56];
493
254
  abyte2 = "\0"*56
494
- # int ai[] = new int[32];
495
255
  ai = [nil]*32
496
- # for (int j1 = 0; j1 < 56; j1++) {
497
- # byte byte0 = V[j1];
498
- # int l2 = byte0 & 7;
499
- # abyte1[j1] = (byte) ( (abyte0[byte0 >>> 3] & bi[l2]) == 0 ? 0 : 1);
500
- # }
501
- # TODO: check impact of >>> substitution with >>
256
+ # TODO: check impact of >>> substitution with >>
502
257
  for j1 in 0...56
503
258
  byte0 = V[j1]
504
259
  l2 = byte0 & 7
505
260
  abyte1[j1] = ( (abyte0[byte0 >> 3] & Bi[l2]) == 0 ? 0 : 1)
506
261
  end
507
- #
508
- # for (int i1 = 0; i1 < 16; i1++) {
509
262
  for i1 in 0...16
510
- # int i3;
511
- # if (flag) {
512
- # i3 = i1 << 1;
513
- # }
514
263
  if (flag)
515
264
  i3 = i1 << 1
516
- # else {
517
- # i3 = 15 - i1 << 1;
518
- # }
519
265
  else
520
266
  i3 = 15 - i1 << 1
521
267
  end
522
- # int j3 = i3 + 1;
523
268
  j3 = i3 + 1
524
- # ai[i3] = ai[j3] = 0;
525
269
  ai[i3] = ai[j3] = 0
526
- # for (int k1 = 0; k1 < 28; k1++) {
527
270
  for k1 in 0...28
528
- # int j2 = k1 + bb[i1];
529
271
  j2 = k1 + Bb[i1]
530
- # if (j2 < 28) {
531
- # abyte2[k1] = abyte1[j2];
532
- # }
533
272
  if (j2 < 28)
534
273
  abyte2[k1] = abyte1[j2]
535
- # else {
536
- # abyte2[k1] = abyte1[j2 - 28];
537
- # }
538
274
  else
539
275
  abyte2[k1] = abyte1[j2 - 28]
540
276
  end
541
- # }
542
277
  end
543
- #
544
- # for (int l1 = 28; l1 < 56; l1++) {
545
278
  for l1 in 28...56
546
- # int k2 = l1 + bb[i1];
547
279
  k2 = l1 + Bb[i1]
548
- # if (k2 < 56) {
549
- # abyte2[l1] = abyte1[k2];
550
- # }
551
280
  if (k2 < 56)
552
281
  abyte2[l1] = abyte1[k2]
553
- # else {
554
- # abyte2[l1] = abyte1[k2 - 28];
555
- # }
556
282
  else
557
283
  abyte2[l1] = abyte1[k2 - 28]
558
284
  end
559
- # }
560
285
  end
561
- #
562
- # for (int i2 = 0; i2 < 24; i2++) {
563
286
  for i2 in 0...24
564
- # if (abyte2[S[i2]] != 0) {
565
- # ai[i3] |= W[i2];
566
- # }
567
287
  if (abyte2[S[i2]] != 0)
568
288
  ai[i3] |= W[i2]
569
289
  end
570
- # if (abyte2[S[i2 + 24]] != 0) {
571
- # ai[j3] |= W[i2];
572
- # }
573
290
  if (abyte2[S[i2 + 24]] != 0)
574
291
  ai[j3] |= W[i2]
575
292
  end
576
- # }
577
293
  end
578
- #
579
- # }
580
294
  end
581
- #
582
- # return C(ai);
583
295
  return c_(ai)
584
- # }
585
296
  end
586
297
 
587
- # static String oldControl(String s1, String s2, int i1) {
588
298
  def old_control(s1, s2, i1)
589
- # if (s1 == null || s2 == null) {
590
- # return null;
591
- # }
592
299
  if (s1 == nil || s2 == nil)
593
300
  return nil
594
301
  end
595
- # byte abyte0[] = A(s1.toCharArray());
596
302
  abyte0 = a_(s1.dup)
597
- # int j1 = s2.length();
598
303
  #j1 = s2.mb_chars.length
599
304
  j1 = s2.length
600
305
 
601
- # if (j1 > i1 - 1) {
602
- # j1 = i1 - 1;
603
- # }
604
306
  if (j1 > i1 - 1)
605
307
  j1 = i1 - 1
606
308
  end
607
- # Random random = new Random();
608
- # RSI: no need to create object here
609
- # int k1 = i1 - j1 - 1;
610
309
  k1 = i1 - j1 - 1
611
- # int ai[] = new int[k1];
612
310
  ai = [nil]*k1
613
- # for (int l1 = 0; l1 < k1; l1++) {
614
- # ai[l1] = random.nextInt();
615
- #
616
- # }
617
- # TODO: substitute Java random.nextInt() with ruby
311
+ # TODO: substitute Java random.nextInt() with ruby
618
312
  for l1 in 0..k1
619
313
  # simulation of random.nextInt()
620
314
  ai[l1] = rand(2**32)-2**31
621
315
  end
622
- # byte abyte1[] = e(ai);
623
316
  abyte1 = e(ai)
624
- # byte abyte2[] = A( (new String(s2 + '\0')).toCharArray());
625
317
  abyte2 = a_( (s2 + "\0") )
626
- # byte abyte3[] = new byte[k1 + abyte2.length];
627
318
  abyte3 = "\0"*(k1 + abyte2.length)
628
- # System.arraycopy(abyte2, 0, abyte3, 0, abyte2.length);
629
319
  abyte3[0, abyte2.length] = abyte2[0, abyte2.length]
630
- # System.arraycopy(abyte1, 0, abyte3, abyte2.length, k1);
631
320
  abyte3[abyte2.length, k1] = abyte1[0, k1]
632
- # byte abyte4[] = k(abyte0, abyte3, i1);
633
321
  abyte4 = k(abyte0, abyte3, i1)
634
- # return z(abyte4);
635
322
  return z(abyte4)
636
- # }
637
323
  end
638
324
 
639
- # private static char[] m(byte abyte0[]) {
640
325
  def m(abyte0)
641
- # char ac1[];
642
- # label0: {
643
326
  while true
644
- # if (abyte0 == null) {
645
- # return null;
646
- # }
647
327
  if (abyte0 == nil)
648
328
  return nil
649
329
  end
650
- # char ac[] = new char[abyte0.length];
651
330
  ac = "\0"*(abyte0.length)
652
- # int i1 = 0;
653
331
  i1 = 0
654
- # boolean flag = false;
655
332
  flag = false
656
- # boolean flag1 = false;
657
333
  flag1 = false
658
- # ac1 = null;
659
334
  ac1 = nil
660
- # try {
661
335
  begin
662
- # for (int j1 = 0; j1 < abyte0.length; j1++) {
663
336
  break_value = for j1 in 0...abyte0.length do
664
- # byte byte0 = abyte0[j1];
665
337
  byte0 = abyte0[j1]
666
- # if ( (byte0 & 0x80) == 0) {
667
- # ac[i1++] = (char) byte0;
668
- # if ( (char) byte0 == 0) {
669
- # break;
670
- # }
671
- # continue;
672
- # }
673
338
  if ( (byte0 & 0x80) == 0)
674
339
  ac[i1] = byte0
675
340
  i1 += 1
@@ -678,16 +343,6 @@ module OracleEbsAuthentication
678
343
  end
679
344
  next
680
345
  end
681
- # if ( (byte0 & 0xe0) == 192) {
682
- # char c1 = (char) ( (byte0 & 0x1f) << 6 & 0x7c0);
683
- # byte0 = abyte0[++j1];
684
- # if ( (byte0 & 0x80) == 128) {
685
- # c1 |= byte0 & 0x3f;
686
- # ac[i1++] = c1;
687
- # continue;
688
- # }
689
- # break label0;
690
- # }
691
346
  if ( (byte0 & 0xe0) == 192)
692
347
  c1 = ( (byte0 & 0x1f) << 6 & 0x7c0)
693
348
  j1 += 1
@@ -700,152 +355,81 @@ module OracleEbsAuthentication
700
355
  end
701
356
  break :label0
702
357
  end
703
- # if ( (byte0 & 0xf0) != 224) {
704
- # continue;
705
- # }
706
358
  if ( (byte0 & 0xf0) != 224)
707
359
  continue
708
360
  end
709
- # char c2 = (char) ( (byte0 & 0xf) << 12 & 0xf000);
710
361
  c2 = ( (byte0 & 0xf) << 12 & 0xf000)
711
- # byte0 = abyte0[++j1];
712
362
  j1 += 1
713
363
  byte0 = abyte0[j1]
714
- # if ( (byte0 & 0x80) != 128) {
715
- # break label0;
716
- # }
717
364
  if ( (byte0 & 0x80) != 128)
718
365
  break :label0
719
366
  end
720
- # c2 |= (byte0 & 0x3f) << 6 & 0xfc0;
721
367
  c2 |= (byte0 & 0x3f) << 6 & 0xfc0
722
- # byte0 = abyte0[++j1];
723
368
  j1 += 1
724
369
  byte0 = abyte0[j1]
725
- # if ( (byte0 & 0x80) != 128) {
726
- # break label0;
727
- # }
728
370
  if ( (byte0 & 0x80) != 128)
729
371
  break :label0
730
372
  end
731
- # c2 |= byte0 & 0x3f;
732
373
  c2 |= byte0 & 0x3f
733
- # ac[i1++] = c2;
734
374
  ac[i1] = c2
735
375
  i1 += 1
736
- # }
737
376
  end
738
377
  # RSI: jump back to label0 if brake was called with :label0
739
378
  if break_value == :label0
740
379
  next
741
380
  end
742
- #
743
- # ac1 = new char[i1];
744
381
  ac1 = "\0"*i1
745
- # System.arraycopy(ac, 0, ac1, 0, i1);
746
382
  ac1[0,i1] = ac[0,i1]
747
- # }
748
- # catch (ArrayIndexOutOfBoundsException _ex) {
749
- # ac1 = null;
750
- # }
751
383
  end
752
- # TODO: when this exception could happen?
753
- # }
754
- # return ac1;
755
- # }
756
- # RSI: if we are here then we should return value and escape endless loop
757
384
  return ac1
758
385
  end
759
386
  end
760
387
 
761
388
 
762
- # private static int n(int i1, int j1, int k1) {
763
- # return i1 ^ j1 ^ k1;
764
- # }
765
389
  def n(i1, j1, k1)
766
390
  return i1 ^ j1 ^ k1
767
391
  end
768
392
 
769
- # private static int o(int i1, int j1, int k1) {
770
- # return i1 ^ j1 ^ k1;
771
- # }
772
393
  def o(i1, j1, k1)
773
394
  return i1 ^ j1 ^ k1
774
395
  end
775
396
 
776
- # static String control(String s1, String s2, int i1) {
777
- # return newControl(s1, s2, 0, i1);
778
- # }
779
397
  def control(s1, s2, i1)
780
398
  return new_control(s1, s2, 0, i1)
781
399
  end
782
400
 
783
- # private static byte[] p(String s1) {
784
401
  def p(s1)
785
- # boolean flag = false;
786
402
  flag = false
787
- # boolean flag1 = false;
788
403
  flag1 = false
789
- # int i1 = 0;
790
404
  i1 = 0
791
- # int j1 = 0;
792
405
  j1 = 0
793
- # byte abyte0[] = null;
794
406
  abyte0 = nil
795
- # if (s1 == null) {
796
- # return null;
797
- # }
798
407
  if (s1 == nil)
799
408
  return nil
800
409
  end
801
- # int k1 = s1.length() / 2;
802
410
  k1 = s1.length / 2
803
- # if (k1 > 0) {
804
411
  if (k1 > 0)
805
- # abyte0 = new byte[k1];
806
412
  abyte0 = "\0"*k1
807
- # for (; k1 > 0; k1--) {
808
413
  while (k1 > 0)
809
- # char c1 = s1.charAt(i1++);
810
414
  #c1 = s1.chars[i1]
811
415
  c1 = s1[i1]
812
416
  i1 += 1
813
- # char c2 = s1.charAt(i1++);
814
417
  #c2 = s1.chars[i1]
815
418
  c2 = s1[i1]
816
419
  i1 += 1
817
- # abyte0[j1++] = (byte) (f(c1) << 4 | f(c2));
818
420
  abyte0[j1] = (f(c1) << 4 | f(c2)) & 0xffffffff
819
421
  j1 += 1
820
- # }
821
422
  k1 -= 1
822
423
  end
823
- #
824
- # }
825
424
  end
826
- # return abyte0;
827
425
  return abyte0
828
- # }
829
426
  end
830
427
 
831
- # private static void q(byte abyte0[], int i1, byte abyte1[], int j1, int ai[],
832
- # int ai1[], int ai2[], byte abyte2[],
833
- # boolean flag) {
834
428
  def q(abyte0, i1, abyte1, j1, ai,
835
429
  ai1, ai2, abyte2,
836
430
  flag)
837
- # byte abyte3[] = new byte[8];
838
431
  abyte3 = "\0"*8
839
- # System.arraycopy(abyte0, i1, abyte3, 0, 8);
840
432
  abyte3[0, 8] = abyte0[i1, 8]
841
- # if (!flag) {
842
- # d(abyte3, ai2);
843
- # d(abyte3, ai1);
844
- # d(abyte3, ai);
845
- # D(abyte3, abyte2, abyte1, j1);
846
- # System.arraycopy(abyte0, i1, abyte2, 0, 8);
847
- # return;
848
- # }
849
433
  if (!flag)
850
434
  # puts "<br/>DEBUG q: initial abyte3=#{abyte3.unpack("H*")[0]}"
851
435
  # puts "<br/>DEBUG q: initial ai2=#{ai2.join(',')}"
@@ -863,15 +447,6 @@ module OracleEbsAuthentication
863
447
  # puts "<br/>DEBUG q: abyte1=#{abyte1.unpack("H*")[0]}"
864
448
  abyte2[0, 8] = abyte0[i1, 8]
865
449
  return
866
- # else {
867
- # D(abyte3, abyte2, abyte3, 0);
868
- # d(abyte3, ai);
869
- # d(abyte3, ai1);
870
- # d(abyte3, ai2);
871
- # System.arraycopy(abyte3, 0, abyte2, 0, 8);
872
- # System.arraycopy(abyte3, 0, abyte1, j1, 8);
873
- # return;
874
- # }
875
450
  else
876
451
  d_(abyte3, abyte2, abyte3, 0);
877
452
  d(abyte3, ai);
@@ -881,220 +456,96 @@ module OracleEbsAuthentication
881
456
  abyte1[j1, 8] = abyte3[0, 8]
882
457
  return
883
458
  end
884
- # }
885
459
  end
886
460
 
887
- # private static int r(int i1, int j1, int k1) {
888
- # return i1 & j1 | ~i1 & k1;
889
- # }
890
461
  def r(i1, j1, k1)
891
462
  return i1 & j1 | ~i1 & k1
892
463
  end
893
464
 
894
- # private static int s(int i1, int j1, int k1) {
895
- # return i1 & j1 | i1 & k1 | j1 & k1;
896
- # }
897
465
  def s(i1, j1, k1)
898
466
  return i1 & j1 | i1 & k1 | j1 & k1
899
467
  end
900
468
 
901
- # static String hash(String s1) {
902
469
  def hash(s1)
903
- # if (s1 == null) {
904
- # return null;
905
- # }
906
470
  if (s1 == nil)
907
471
  return nil
908
472
  end
909
- # byte abyte0[];
910
- # try {
911
- # abyte0 = s1.getBytes("UTF8");
912
- # }
913
- # catch (UnsupportedEncodingException _ex) {
914
- # return null;
915
- # }
916
473
  abyte0 = s1.dup
917
- # byte abyte1[] = y(null, abyte0);
918
474
  abyte1 = y(nil, abyte0)
919
- # return z(abyte1);
920
475
  return z(abyte1)
921
- # }
922
476
  end
923
477
 
924
- # static String newControl(String s1, String s2, int i1, int j1) {
925
478
  def new_control(s1, s2, i1, j1)
926
- # if (s1 == null || s2 == null) {
927
- # return "ZG_ENCRYPT_FAILED_BADINPUT";
928
- # }
929
479
  if (s1 == nil || s2 == nil)
930
480
  return "ZG_ENCRYPT_FAILED_BADINPUT"
931
481
  end
932
- # int k1;
933
- # if (i1 > 0) {
934
- # k1 = i1;
935
- # }
936
482
  if (i1 > 0)
937
483
  k1 = i1
938
- # else
939
- # if (j1 == 32) {
940
- # k1 = 100;
941
- # }
942
484
  elsif (j1 == 32)
943
485
  k1 = 100
944
- # else
945
- # if (j1 < 32 && j1 == s2.length()) {
946
- # k1 = 100;
947
- # }
948
486
  elsif (j1 < 32 && j1 == s2.length())
949
487
  k1 = 100
950
- # else {
951
- # byte abyte1[];
952
- # try {
953
- # abyte1 = s2.getBytes("UTF8");
954
- # }
955
- # catch (UnsupportedEncodingException _ex) {
956
- # return "ZG_ENCRYPT_FAILED_MISC";
957
- # }
958
- # k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14;
959
- # }
960
488
  else
961
489
  abyte1 = s2.dup
962
490
  k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14
963
491
  end
964
- # int l1 = 1;
965
492
  l1 = 1
966
- # byte byte0 = 2;
967
493
  byte0 = 2
968
- # int i2 = k1 - 2 - l1 * 2;
969
494
  i2 = k1 - 2 - l1 * 2
970
- # if (i2 <= 0) {
971
- # return "ZG_ENCRYPT_FAILED_SMALLBUF";
972
- # }
973
495
  if (i2 <= 0)
974
496
  return "ZG_ENCRYPT_FAILED_SMALLBUF"
975
497
  end
976
- # int j2 = (i2 / 16) * 8;
977
498
  j2 = (i2 / 16) * 8
978
- # if (j2 <= 0) {
979
- # return "ZG_ENCRYPT_FAILED_SMALLBUF";
980
- # }
981
499
  if (j2 <= 0)
982
500
  return "ZG_ENCRYPT_FAILED_SMALLBUF"
983
501
  end
984
- # int k2 = (i2 % 16) / 2;
985
502
  k2 = (i2 % 16) / 2
986
- # int l2 = k2 + l1;
987
503
  l2 = k2 + l1
988
- # int i3 = j2 - 1 - byte0;
989
504
  i3 = j2 - 1 - byte0
990
- # if (i3 <= 0) {
991
- # return "ZG_ENCRYPT_FAILED_SMALLBUF";
992
- # }
993
505
  if (i3 <= 0)
994
506
  return "ZG_ENCRYPT_FAILED_SMALLBUF"
995
507
  end
996
- # byte abyte0[];
997
- # byte abyte2[];
998
- # try {
999
- # abyte0 = s1.getBytes("UTF8");
1000
- # abyte2 = s2.getBytes("UTF8");
1001
- # }
1002
- # catch (UnsupportedEncodingException _ex) {
1003
- # return "ZG_ENCRYPT_FAILED_MISC";
1004
- # }
1005
508
  abyte0 = s1.dup
1006
509
  abyte2 = s2.dup
1007
- # int j3 = abyte0.length;
1008
510
  j3 = abyte0.length
1009
- # int k3 = abyte2.length;
1010
511
  k3 = abyte2.length
1011
- # if (k3 > i3) {
1012
- # return "ZG_ENCRYPT_FAILED_CHARSET_CLIP";
1013
- # }
1014
512
  if (k3 > i3)
1015
513
  return "ZG_ENCRYPT_FAILED_CHARSET_CLIP"
1016
514
  end
1017
- # Random random = new Random();
1018
- # int ai[] = new int[l2];
1019
515
  ai = [nil]*l2
1020
- # for (int l3 = 0; l3 < l2; l3++) {
1021
- # ai[l3] = random.nextInt();
1022
- #
1023
- # }
1024
516
  for l3 in 0...l2
1025
517
  ai[l3] = rand(2**32)-2**31
1026
518
  end
1027
- # byte abyte3[] = e(ai);
1028
519
  abyte3 = e(ai)
1029
- # ai = null;
1030
520
  ai = nil
1031
- # byte byte1 = byte0;
1032
521
  byte1 = byte0
1033
- # ai = new int[byte1];
1034
522
  ai = [nil]*byte1
1035
- # for (int i4 = 0; i4 < byte1; i4++) {
1036
- # ai[i4] = random.nextInt();
1037
- #
1038
- # }
1039
523
  for i4 in 0...byte1
1040
524
  ai[i4] = rand(2**32)-2**31
1041
525
  end
1042
- # byte abyte4[] = e(ai);
1043
526
  abyte4 = e(ai)
1044
- # ai = null;
1045
527
  ai = nil
1046
- # int j4 = i3 - k3;
1047
528
  j4 = i3 - k3
1048
- # ai = new int[j4];
1049
529
  ai = [nil]*j4
1050
- # for (int k4 = 0; k4 < j4; k4++) {
1051
530
  for k4 in 0...j4
1052
- # if (k4 == 0) {
1053
- # ai[k4] = 0;
1054
- # }
1055
531
  if (k4 == 0)
1056
532
  ai[k4] = 0
1057
- # else {
1058
- # ai[k4] = random.nextInt();
1059
- #
1060
- # }
1061
533
  else
1062
534
  ai[k4] = rand(2**32)-2**31
1063
535
  end
1064
- # }
1065
536
  end
1066
- # byte abyte5[] = e(ai);
1067
537
  abyte5 = e(ai)
1068
- # ai = null;
1069
538
  ai = nil
1070
- # byte abyte6[] = new byte[byte1 + j4 + k3];
1071
539
  abyte6 = "\0"*(byte1 + j4 + k3)
1072
- # System.arraycopy(abyte4, 0, abyte6, 0, byte1);
1073
540
  abyte6[0, byte1] = abyte4[0, byte1]
1074
- # System.arraycopy(abyte2, 0, abyte6, byte1, k3);
1075
541
  abyte6[byte1, k3] = abyte2[0, k3]
1076
- # System.arraycopy(abyte5, 0, abyte6, byte1 + k3, j4);
1077
542
  abyte6[byte1+k3, j4] = abyte5[0, j4]
1078
- # byte abyte7[] = new byte[l2 + j3];
1079
543
  abyte7 = "\0"*(l2 + j3)
1080
- # System.arraycopy(abyte3, 0, abyte7, 0, l2);
1081
544
  abyte7[0, l2] = abyte3[0, l2]
1082
- # System.arraycopy(abyte0, 0, abyte7, l2, j3);
1083
545
  abyte7[l2, j3] = abyte0[0, j3]
1084
- # byte abyte8[] = i(null, abyte7, abyte6);
1085
546
  abyte8 = i(nil, abyte7, abyte6)
1086
- # if (abyte8 == null) {
1087
- # return "ZG_ENCRYPT_FAILED_MISC";
1088
- # }
1089
547
  if (abyte8 == nil)
1090
548
  return "ZG_ENCRYPT_FAILED_MISC"
1091
- # else {
1092
- # byte abyte9[] = new byte[abyte8.length + l2];
1093
- # System.arraycopy(abyte8, 0, abyte9, 0, abyte8.length);
1094
- # System.arraycopy(abyte3, 0, abyte9, abyte8.length, l2);
1095
- # String s3 = z(abyte9);
1096
- # return "ZG" + s3;
1097
- # }
1098
549
  else
1099
550
  abyte9 = "\0"*(abyte8.length + l2)
1100
551
  abyte9[0, abyte8.length] = abyte8[0, abyte8.length]
@@ -1102,108 +553,53 @@ module OracleEbsAuthentication
1102
553
  s3 = z(abyte9)
1103
554
  return "ZG" + s3
1104
555
  end
1105
- # }
1106
556
  end
1107
557
 
1108
- # private static void t(byte abyte0[], int ai[]) {
1109
558
  def t(abyte0, ai)
1110
- # int i1 = 0;
1111
559
  i1 = 0
1112
- # ai[0] = (abyte0[i1] & 0xff) << 24;
1113
560
  ai[0] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
1114
- # i1++;
1115
561
  i1 += 1
1116
- # ai[0] |= (abyte0[i1] & 0xff) << 16;
1117
562
  ai[0] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
1118
- # i1++;
1119
563
  i1 += 1
1120
- # ai[0] |= (abyte0[i1] & 0xff) << 8;
1121
564
  ai[0] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
1122
- # i1++;
1123
565
  i1 += 1
1124
- # ai[0] |= abyte0[i1] & 0xff;
1125
566
  ai[0] |= abyte0[i1] & 0xff
1126
- # i1++;
1127
567
  i1 += 1
1128
- # ai[1] = (abyte0[i1] & 0xff) << 24;
1129
568
  ai[1] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
1130
- # i1++;
1131
569
  i1 += 1
1132
- # ai[1] |= (abyte0[i1] & 0xff) << 16;
1133
570
  ai[1] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
1134
- # i1++;
1135
571
  i1 += 1
1136
- # ai[1] |= (abyte0[i1] & 0xff) << 8;
1137
572
  ai[1] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
1138
- # i1++;
1139
573
  i1 += 1
1140
- # ai[1] |= abyte0[i1] & 0xff;
1141
574
  ai[1] |= abyte0[i1] & 0xff
1142
- # }
1143
575
  end
1144
576
 
1145
- # private static int u(int ai[], int ai1[]) {
1146
577
  def u(ai, ai1)
1147
- # boolean flag = false;
1148
578
  flag = false
1149
- # boolean flag1 = false;
1150
579
  flag1 = false
1151
- # int ai2[] = new int[80];
1152
580
  ai2 = [nil]*80
1153
- # int l1 = 0;
1154
581
  l1 = 0
1155
- # int ai3[] = new int[5];
1156
582
  ai3 = [nil]*5
1157
- # int ai4[] = new int[6];
1158
583
  ai4 = [nil]*6
1159
- # int ai5[] = new int[5];
1160
584
  ai5 = [nil]*5
1161
- # ai3[0] = 0x67452301;
1162
- # ai3[1] = 0xefcdab89;
1163
- # ai3[2] = 0x98badcfe;
1164
- # ai3[3] = 0x10325476;
1165
- # ai3[4] = 0xc3d2e1f0;
1166
585
  ai3[0] = 0x67452301
1167
586
  ai3[1] = 0xefcdab89
1168
587
  ai3[2] = 0x98badcfe
1169
588
  ai3[3] = 0x10325476
1170
589
  ai3[4] = 0xc3d2e1f0
1171
- # if (ai1 != null) {
1172
590
  if (ai1 != nil)
1173
- # if (ai != null) {
1174
- # System.arraycopy(ai, 0, ai4, 0, 5);
1175
- # }
1176
591
  if (ai != nil)
1177
592
  ai4[0, 5] = ai[0, 5]
1178
593
  end
1179
- # byte byte0 = 80;
1180
594
  byte0 = 80
1181
- # int i1;
1182
- # for (i1 = 0; i1 < 16; i1++) {
1183
- # ai2[i1] = ai1[i1];
1184
- #
1185
- # }
1186
595
  for i1 in 0...16
1187
596
  ai2[i1] = ai1[i1]
1188
597
  end
1189
- # for (; i1 < byte0; i1++) {
1190
- # ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16];
1191
- #
1192
- # }
1193
598
  while (i1 < byte0)
1194
599
  ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16]
1195
600
  i1 += 1
1196
601
  end
1197
- # for (int j1 = 0; j1 < 80; j1++) {
1198
602
  for j1 in 0...80
1199
- # if (j1 != 0) {
1200
- # System.arraycopy(ai4, 0, ai5, 0, 5);
1201
- # ai4[0] = ai5[4];
1202
- # ai4[1] = ai5[0];
1203
- # ai4[2] = ai5[1];
1204
- # ai4[3] = ai5[2];
1205
- # ai4[4] = ai5[3];
1206
- # }
1207
603
  if (j1 != 0)
1208
604
  ai5[0, 5] = ai4[0, 5]
1209
605
  ai4[0] = ai5[4];
@@ -1212,61 +608,26 @@ module OracleEbsAuthentication
1212
608
  ai4[3] = ai5[2];
1213
609
  ai4[4] = ai5[3];
1214
610
  end
1215
- # ai4[5] = ai2[j1];
1216
611
  ai4[5] = ai2[j1]
1217
- # if (j1 < 20) {
1218
- # H(ai4);
1219
- # }
1220
612
  if (j1 < 20)
1221
613
  h_(ai4)
1222
- # else
1223
- # if (j1 < 40) {
1224
- # I(ai4);
1225
- # }
1226
614
  elsif (j1 < 40)
1227
615
  i_(ai4)
1228
- # else
1229
- # if (j1 < 60) {
1230
- # c(ai4);
1231
- # }
1232
616
  elsif (j1 < 60)
1233
617
  c(ai4)
1234
- # else
1235
- # if (j1 < 80) {
1236
- # h(ai4);
1237
- # }
1238
618
  elsif (j1 < 80)
1239
619
  h(ai4)
1240
620
  end
1241
- # }
1242
621
  end
1243
- #
1244
- # ai3[0] = ai4[4];
1245
- # ai3[1] = ai4[0];
1246
- # ai3[2] = ai4[1];
1247
- # ai3[3] = ai4[2];
1248
- # ai3[4] = ai4[3];
1249
622
  ai3[0] = ai4[4];
1250
623
  ai3[1] = ai4[0];
1251
624
  ai3[2] = ai4[1];
1252
625
  ai3[3] = ai4[2];
1253
626
  ai3[4] = ai4[3];
1254
- # for (int k1 = 0; k1 < byte0; k1++) {
1255
- # ai2[k1] = 0;
1256
- #
1257
- # }
1258
627
  for k1 in 0...byte0
1259
628
  ai2[k1] = 0
1260
629
  end
1261
- # }
1262
630
  end
1263
- # if (ai != null) {
1264
- # ai[0] = ai3[0];
1265
- # ai[1] = ai3[1];
1266
- # ai[2] = ai3[2];
1267
- # ai[3] = ai3[3];
1268
- # ai[4] = ai3[4];
1269
- # }
1270
631
  if (ai != nil)
1271
632
  ai[0] = ai3[0];
1272
633
  ai[1] = ai3[1];
@@ -1274,263 +635,118 @@ module OracleEbsAuthentication
1274
635
  ai[3] = ai3[3];
1275
636
  ai[4] = ai3[4];
1276
637
  end
1277
- # l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4];
1278
638
  l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4]
1279
- # return l1;
1280
639
  return l1
1281
- # }
1282
640
  end
1283
641
 
1284
- # private static byte[] v(byte abyte0[], byte abyte1[], byte abyte2[]) {
1285
- # return g(y(abyte0, abyte1), abyte2);
1286
- # }
1287
642
  def v(abyte0, abyte1, abyte2)
1288
643
  return g(y(abyte0, abyte1), abyte2)
1289
644
  end
1290
645
 
1291
- # private static String w(String s1, int i1, boolean flag) {
1292
646
  def w(s1, i1, flag)
1293
- # if (s1 == null) {
1294
- # return "";
1295
- # }
1296
647
  if (s1 == nil)
1297
648
  return ""
1298
649
  end
1299
- # int j1 = s1.length();
1300
- # TODO: should String be converted to Ruby Unicode chars string?
1301
650
  j1 = s1.length
1302
- # int k1 = s1.indexOf('\0');
1303
651
  k1 = s1.index("\0")
1304
- # if (k1 > -1) {
1305
- # j1 = k1;
1306
- # }
1307
652
  if (k1 > -1)
1308
653
  j1 = k1
1309
654
  end
1310
- # int l1;
1311
- # if (j1 > i1 && i1 > 0) {
1312
- # l1 = i1;
1313
- # }
1314
655
  if (j1 > i1 && i1 > 0)
1315
656
  l1 = i1
1316
- # else {
1317
- # l1 = j1;
1318
- # }
1319
657
  else
1320
658
  l1 = j1
1321
659
  end
1322
- # if (flag) {
1323
- # return new String(s1.substring(0, l1).toUpperCase(Locale.US));
1324
- # }
1325
660
  if (flag)
1326
661
  # TODO: should we do Unicode upcase?
1327
662
  return s1[0, l1].upcase
1328
- # else {
1329
- # return new String(s1.substring(0, l1));
1330
- # }
1331
663
  else
1332
664
  return s1[0, l1]
1333
665
  end
1334
- # }
1335
666
  end
1336
667
 
1337
- # private static void x(int ai[], byte abyte0[]) {
1338
668
  def x(ai, abyte0)
1339
- # int i1 = 0;
1340
669
  i1 = 0
1341
- # abyte0[i1] = (byte) (ai[0] >> 24 & 0xff);
1342
670
  abyte0[i1] = (ai[0] >> 24 & 0xff)
1343
- # i1++;
1344
671
  i1 += 1
1345
- # abyte0[i1] = (byte) (ai[0] >> 16 & 0xff);
1346
672
  abyte0[i1] = (ai[0] >> 16 & 0xff)
1347
- # i1++;
1348
673
  i1 += 1
1349
- # abyte0[i1] = (byte) (ai[0] >> 8 & 0xff);
1350
674
  abyte0[i1] = (ai[0] >> 8 & 0xff)
1351
- # i1++;
1352
675
  i1 += 1
1353
- # abyte0[i1] = (byte) (ai[0] & 0xff);
1354
676
  abyte0[i1] = (ai[0] & 0xff)
1355
- # i1++;
1356
677
  i1 += 1
1357
- # abyte0[i1] = (byte) (ai[1] >> 24 & 0xff);
1358
678
  abyte0[i1] = (ai[1] >> 24 & 0xff)
1359
- # i1++;
1360
679
  i1 += 1
1361
- # abyte0[i1] = (byte) (ai[1] >> 16 & 0xff);
1362
680
  abyte0[i1] = (ai[1] >> 16 & 0xff)
1363
- # i1++;
1364
681
  i1 += 1
1365
- # abyte0[i1] = (byte) (ai[1] >> 8 & 0xff);
1366
682
  abyte0[i1] = (ai[1] >> 8 & 0xff)
1367
- # i1++;
1368
683
  i1 += 1
1369
- # abyte0[i1] = (byte) (ai[1] & 0xff);
1370
684
  abyte0[i1] = (ai[1] & 0xff)
1371
- # }
1372
685
  end
1373
686
 
1374
- # static String oldCheck(String s1, String s2, boolean flag) {
1375
687
  def old_check(s1, s2, flag)
1376
- # byte abyte0[] = A(s1.toCharArray());
1377
688
  abyte0 = a_(s1.dup)
1378
- # byte abyte1[] = p(s2);
1379
689
  abyte1 = p(s2)
1380
- # byte abyte2[] = k(abyte0, abyte1, abyte1.length);
1381
690
  abyte2 = k(abyte0, abyte1, abyte1.length)
1382
- # char ac[] = m(abyte2);
1383
691
  ac = m(abyte2)
1384
- # if (ac != null) {
1385
- # String s3 = new String(ac);
1386
- # return w(s3, 0, flag);
1387
- # }
1388
692
  if (ac != nil)
1389
693
  s3 = ac.to_s
1390
- # else {
1391
- # return null;
1392
- # }
1393
694
  else
1394
695
  return nil
1395
696
  end
1396
- # }
1397
697
  end
1398
698
 
1399
- # private static byte[] y(byte abyte0[], byte abyte1[]) {
1400
699
  def y(abyte0, abyte1)
1401
700
  # puts "<br/>DEBUG y: abyte0=#{abyte0.nil? ? "nil" : abyte0.unpack("H*")[0]}"
1402
701
  # puts "<br/>DEBUG y: abyte1=#{abyte1.nil? ? "nil" : abyte1.unpack("H*")[0]}"
1403
- # byte abyte2[] = new byte[32];
1404
702
  abyte2 = "\0"*32
1405
- # MessageDigest messagedigest;
1406
- # try {
1407
- # messagedigest = MessageDigest.getInstance("SHA");
1408
- # }
1409
- # catch (NoSuchAlgorithmException _ex) {
1410
- # return null;
1411
- # }
1412
703
  messagedigest = Digest::SHA1.new
1413
- # messagedigest.reset();
1414
704
  messagedigest.reset
1415
- # byte byte0 = 20;
1416
705
  byte0 = 20
1417
- # if (abyte0 != null && abyte0.length > 0) {
1418
- # messagedigest.update(abyte0);
1419
- # }
1420
706
  if (abyte0 != nil && abyte0.length > 0)
1421
707
  messagedigest.update(abyte0)
1422
708
  end
1423
- # if (abyte1 != null && abyte1.length > 0) {
1424
- # messagedigest.update(abyte1);
1425
- # }
1426
709
  if (abyte1 != nil && abyte1.length > 0)
1427
710
  messagedigest.update(abyte1)
1428
711
  end
1429
- # messagedigest.update( (byte) 1);
1430
712
  messagedigest.update(1.chr)
1431
- # byte abyte3[] = messagedigest.digest();
1432
713
  abyte3 = messagedigest.digest
1433
714
  # puts "<br/>DEBUG y: abyte3=#{abyte3.nil? ? "nil" : abyte3.unpack("H*")[0]}"
1434
- # System.arraycopy(abyte3, 0, abyte2, 0, byte0);
1435
715
  abyte2[0, byte0] = abyte3[0, byte0]
1436
- # messagedigest.reset();
1437
716
  messagedigest.reset()
1438
- # if (abyte0 != null && abyte0.length > 0) {
1439
- # messagedigest.update(abyte0);
1440
- # }
1441
717
  if (abyte0 != nil && abyte0.length > 0)
1442
718
  messagedigest.update(abyte0)
1443
719
  end
1444
- # if (abyte1 != null && abyte1.length > 0) {
1445
- # messagedigest.update(abyte1);
1446
- # }
1447
720
  if (abyte1 != nil && abyte1.length > 0)
1448
721
  messagedigest.update(abyte1)
1449
722
  end
1450
- # messagedigest.update( (byte) 2);
1451
723
  messagedigest.update( 2.chr )
1452
- # abyte3 = messagedigest.digest();
1453
724
  abyte3 = messagedigest.digest
1454
- # System.arraycopy(abyte3, 0, abyte2, byte0, 32 - byte0);
1455
725
  abyte2[byte0, 32 - byte0] = abyte3[0, 32 - byte0]
1456
- # return abyte2;
1457
726
  # puts "<br/>DEBUG y: abyte2=#{abyte2.unpack("H*")[0]}"
1458
727
  return abyte2
1459
- # }
1460
728
  end
1461
729
 
1462
- # private static String z(byte abyte0[]) {
1463
730
  def z(abyte0)
1464
- # # if (abyte0 == null) {
1465
- # # return null;
1466
- # # }
1467
- # if (abyte0 == nil)
1468
- # return nil
1469
- # end
1470
- # # String s1 = "0123456789ABCDEF";
1471
- # s1 = "0123456789ABCDEF"
1472
- # # StringBuffer stringbuffer = new StringBuffer(abyte0.length * 2);
1473
- # stringbuffer = ""
1474
- # # int i1 = 0;
1475
- # i1 = 0
1476
- # # for (int j1 = abyte0.length; j1 > 0; ) {
1477
- # j1 = abyte0.length
1478
- # while (j1 > 0)
1479
- # # byte byte0 = abyte0[i1];
1480
- # byte0 = abyte0[i1]
1481
- # # stringbuffer.append(s1.charAt(byte0 >> 4 & 0xf));
1482
- # stringbuffer << s1[byte0 >> 4 & 0xf]
1483
- # # stringbuffer.append(s1.charAt(byte0 & 0xf));
1484
- # stringbuffer << s1[byte0 & 0xf]
1485
- # # j1--;
1486
- # j1 -= 1
1487
- # # i1++;
1488
- # i1 += 1
1489
- # # }
1490
- # end
1491
- # #
1492
- # # return stringbuffer.toString();
1493
- # return stringbuffer
1494
- # # }
1495
731
  abyte0.unpack("H*")[0].upcase
1496
732
  end
1497
733
 
1498
- # private static byte[] A(char ac[]) {
1499
734
  def a_(ac)
1500
735
  # RSI: if we receive String then return the same value (as it should already be in UTF-8)
1501
736
  return ac if ac.is_a? String
1502
- # byte abyte0[] = new byte[ac.length * 3];
1503
737
  abyte0 = "\0"*(ac.length * 3)
1504
- # int i1 = 0;
1505
738
  i1 = 0
1506
- # boolean flag = false;
1507
739
  flag = false
1508
- # for (int j1 = 0; j1 < ac.length; j1++) {
1509
740
  for j1 in 0...ac.length
1510
- # char c1 = ac[j1];
1511
741
  c1 = ac[j1]
1512
- # if (c1 >= 0 && c1 <= '\177') {
1513
- # abyte0[i1++] = (byte) (c1 & 0x7f);
1514
- # }
1515
742
  if (c1 >= 0 && c1 <= 0177)
1516
743
  abyte0[i1] = (c1 & 0x7f)
1517
744
  i1 += 1
1518
- # else
1519
- # if (c1 >= '\200' && c1 <= '\u07FF') {
1520
- # abyte0[i1++] = (byte) ( (c1 & 0x7c0) >> 6 | 0xc0);
1521
- # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
1522
- # }
1523
745
  elsif (c1 >= 0200 && c1 <= 0x07FF)
1524
746
  abyte0[i1] = ( (c1 & 0x7c0) >> 6 | 0xc0)
1525
747
  i1 += 1
1526
748
  abyte0[i1] = (c1 & 0x3f | 0x80)
1527
749
  i1 += 1
1528
- # else
1529
- # if (c1 >= '\u0800' && c1 <= '\uFFFF') {
1530
- # abyte0[i1++] = (byte) ( (c1 & 0xf000) >> 12 | 0xe0);
1531
- # abyte0[i1++] = (byte) ( (c1 & 0xfc0) >> 6 | 0x80);
1532
- # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
1533
- # }
1534
750
  elsif (c1 >= 0x0800 && c1 <= 0xFFFF)
1535
751
  abyte0[i1] = ( (c1 & 0xf000) >> 12 | 0xe0)
1536
752
  i1 += 1
@@ -1539,60 +755,28 @@ module OracleEbsAuthentication
1539
755
  abyte0[i1] = (c1 & 0x3f | 0x80)
1540
756
  i1 += 1
1541
757
  end
1542
- # }
1543
758
  end
1544
- #
1545
- # byte abyte1[] = new byte[i1];
1546
759
  abyte1 = "\0"*i1
1547
- # System.arraycopy(abyte0, 0, abyte1, 0, i1);
1548
760
  abyte1[0, i1] = abyte0[0, i1]
1549
- # return abyte1;
1550
761
  abyte1
1551
- # }
1552
762
  end
1553
763
 
1554
- # private static void B(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
1555
764
  def b_(abyte0, abyte1, abyte2, i1)
1556
- # if (abyte0 == null) {
1557
765
  if (abyte0 == nil)
1558
- # if (i1 > 0 && abyte1 != null && abyte2 != null) {
1559
766
  if (i1 > 0 && abyte1 != nil && abyte2 != nil)
1560
- # for (int j1 = 0; j1 < i1; j1++) {
1561
- # abyte2[j1] = abyte1[j1];
1562
- #
1563
- # }
1564
767
  for j1 in 0...i1
1565
768
  abyte2[j1] = abyte1[j1]
1566
769
  end
1567
- # return;
1568
770
  return
1569
- # }
1570
771
  end
1571
- # }
1572
- # else {
1573
- # if (abyte2 == null) {
1574
772
  else
1575
773
  if (abyte2 == nil)
1576
- # for (int k1 = 0; k1 < 256; k1++) {
1577
- # abyte0[k1] = (byte) k1;
1578
- #
1579
- # }
1580
774
  for k1 in 0...256
1581
775
  abyte0[k1] = k1
1582
776
  end
1583
- # if (abyte1 != null && i1 > 0) {
1584
777
  if (abyte1 != nil && i1 > 0)
1585
- # int j2 = 0;
1586
778
  j2 = 0
1587
- # int l2 = 0;
1588
779
  l2 = 0
1589
- # for (int l1 = 0; l1 < 256; l1++) {
1590
- # int j3 = (new Byte(abyte0[l1])).intValue() & 0xff;
1591
- # j2 = j2 + j3 + ( (new Byte(abyte1[l2])).intValue() & 0xff) & 0xff;
1592
- # abyte0[l1] = abyte0[j2];
1593
- # abyte0[j2] = (new Integer(j3 & 0xff)).byteValue();
1594
- # l2 = (l2 + 1) % i1;
1595
- # }
1596
780
  for l1 in 0...256
1597
781
  j3 = abyte0[l1] & 0xff
1598
782
  j2 = j2 + j3 + ( abyte1[l2] & 0xff) & 0xff
@@ -1600,399 +784,200 @@ module OracleEbsAuthentication
1600
784
  abyte0[j2] = j3 & 0xff
1601
785
  l2 = (l2 + 1) % i1
1602
786
  end
1603
- #
1604
- # }
1605
787
  end
1606
- # abyte0[256] = 0;
1607
788
  abyte0[256] = 0
1608
- # abyte0[257] = 0;
1609
789
  abyte0[257] = 0
1610
- # return;
1611
790
  return
1612
- # }
1613
791
  end
1614
- # int i2 = (new Byte(abyte0[256])).intValue() & 0xff;
1615
792
  i2 = abyte0[256] & 0xff
1616
- # int k2 = (new Byte(abyte0[257])).intValue() & 0xff;
1617
793
  k2 = abyte0[257] & 0xff
1618
- # for (int i3 = 0; i3 < i1; i3++) {
1619
794
  for i3 in 0...i1
1620
- # i2 = i2 + 1 & 0xff;
1621
795
  i2 = i2 + 1 & 0xff
1622
- # int k3 = (new Byte(abyte0[i2])).intValue() & 0xff;
1623
796
  k3 = abyte0[i2] & 0xff
1624
- # k2 = k2 + k3 & 0xff;
1625
797
  k2 = k2 + k3 & 0xff
1626
- # abyte0[i2] = abyte0[k2];
1627
798
  abyte0[i2] = abyte0[k2]
1628
- # abyte0[k2] = (new Integer(k3 & 0xff)).byteValue();
1629
799
  abyte0[k2] = k3 & 0xff
1630
- # k3 += (new Byte(abyte0[i2])).intValue() & 0xff;
1631
800
  k3 += abyte0[i2] & 0xff
1632
- # abyte2[i3] = (byte) (abyte1[i3] ^ abyte0[k3 & 0xff]);
1633
801
  abyte2[i3] = (abyte1[i3] ^ abyte0[k3 & 0xff])
1634
- # new String("");
1635
802
  ""
1636
- # }
1637
803
  end
1638
- #
1639
- # abyte0[256] = (byte) (i2 & 0xff);
1640
804
  abyte0[256] = (i2 & 0xff)
1641
- # abyte0[257] = (byte) (k2 & 0xff);
1642
805
  abyte0[257] = (k2 & 0xff)
1643
- # }
1644
806
  end
1645
- # }
1646
807
  end
1647
808
 
1648
- # static boolean check(String s1, String s2, boolean flag) {
1649
809
  def check(s1, s2, flag)
1650
810
  return true if decrypt(s1, s2, flag)
1651
811
  false
1652
812
  end
1653
813
 
1654
814
  def decrypt(s1, s2, flag)
1655
- # String cid;
1656
- # if (s2 != null && s2.length() > 0) {
1657
815
  if (s2 != nil && s2.length() > 0)
1658
- # if (s2.substring(0, 2).equals("ZG")) {
1659
- # cid = newCheck(s1, s2, flag);
1660
- # }
1661
816
  if (s2[0, 2] == "ZG")
1662
817
  # EBEI: Upcase case-insensitive passwords
1663
818
  cid = new_check(s1.mb_chars.upcase.to_s, s2, flag)
1664
819
  # EBEI: Support case sensitive passwords in R12
1665
820
  elsif s2[0, 2] == "ZH"
1666
821
  cid = new_check(s1, s2.gsub(/^ZH/, 'ZG'), flag)
1667
- # else {
1668
- # cid= oldCheck(s1, s2, flag);
1669
- # }
1670
822
  else
1671
823
  cid = old_check(s1, s2, flag)
1672
824
  end
1673
- # }
1674
- # else {
1675
- # return false;
1676
- # }
1677
825
  else
1678
826
  return false
1679
827
  end
1680
- # if (cid==null) {
1681
- # return false;
1682
- # } else {
1683
- # return true;
1684
- # }
1685
828
  return cid
1686
- # }
1687
829
  end
1688
-
1689
- # private static int[] C(int ai[]) {
830
+
1690
831
  def c_(ai)
1691
- # int ai1[] = new int[32];
1692
832
  ai1 = [nil]*32
1693
- # int ai2[] = ai;
1694
833
  ai2 = ai
1695
- # int i1 = 0;
1696
834
  i1 = 0
1697
- # boolean flag = false;
1698
835
  flag = false
1699
- # int k1 = 0;
1700
836
  k1 = 0
1701
- # int l1 = 0;
1702
837
  l1 = 0
1703
- # while (i1 < 16) {
1704
838
  while (i1 < 16)
1705
- # int j1 = k1++;
1706
839
  j1 = k1
1707
840
  k1 += 1
1708
- # ai1[l1] = (ai2[j1] & 0xfc0000) << 6;
1709
841
  ai1[l1] = (ai2[j1] & 0xfc0000) << 6
1710
- # ai1[l1] |= (ai2[j1] & 0xfc0) << 10;
1711
842
  ai1[l1] |= (ai2[j1] & 0xfc0) << 10
1712
- # ai1[l1] |= (ai[k1] & 0xfc0000) >> 10;
1713
843
  ai1[l1] |= (ai[k1] & 0xfc0000) >> 10
1714
- # ai1[l1] |= (ai[k1] & 0xfc0) >> 6;
1715
844
  ai1[l1] |= (ai[k1] & 0xfc0) >> 6
1716
- # l1++;
1717
845
  l1 += 1
1718
- # ai1[l1] = (ai2[j1] & 0x3f000) << 12;
1719
846
  ai1[l1] = (ai2[j1] & 0x3f000) << 12
1720
- # ai1[l1] |= (ai2[j1] & 0x3f) << 16;
1721
847
  ai1[l1] |= (ai2[j1] & 0x3f) << 16
1722
- # ai1[l1] |= (ai[k1] & 0x3f000) >> 4;
1723
848
  ai1[l1] |= (ai[k1] & 0x3f000) >> 4
1724
- # ai1[l1] |= ai[k1] & 0x3f;
1725
849
  ai1[l1] |= ai[k1] & 0x3f
1726
- # l1++;
1727
850
  l1 += 1
1728
- # i1++;
1729
851
  i1 += 1
1730
- # k1++;
1731
852
  k1 += 1
1732
- # }
1733
853
  end
1734
- # return ai1;
1735
854
  return ai1
1736
- # }
1737
855
  end
1738
856
 
1739
- # private static void D(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
1740
857
  def d_(abyte0, abyte1, abyte2, i1)
1741
- # for (int j1 = 0; j1 < 8; j1++) {
1742
- # abyte2[j1 + i1] = (byte) (abyte0[j1] ^ abyte1[j1]);
1743
- #
1744
- # }
1745
858
  for j1 in 0...8
1746
859
  abyte2[j1 + i1] = (abyte0[j1] ^ abyte1[j1])
1747
860
  end
1748
- # }
1749
861
  end
1750
862
 
1751
- # private static void E(String s1) {
1752
- # }
1753
863
  def e_(s1)
1754
864
  end
1755
865
 
1756
- # private static void F(int ai[], int ai1[]) {
1757
866
  def f_(ai, ai1)
1758
- # int j2 = 0;
1759
867
  j2 = 0
1760
- # int l1 = ai[0];
1761
868
  l1 = ai[0]
1762
- # int k1 = ai[1];
1763
869
  k1 = ai[1]
1764
- # int j1 = (l1 >>> 4 ^ k1) & 0xf0f0f0f;
1765
- # TODO: check that it is safe to replace >>> with >>
1766
870
  j1 = (l1 >> 4 ^ k1) & 0xf0f0f0f
1767
- # k1 ^= j1;
1768
871
  k1 ^= j1
1769
- # l1 ^= j1 << 4;
1770
872
  l1 ^= (j1 << 4) & 0xffffffff
1771
- # j1 = (l1 >>> 16 ^ k1) & 0xffff;
1772
- # TODO: check that it is safe to replace >>> with >>
1773
873
  j1 = (l1 >> 16 ^ k1) & 0xffff
1774
- # k1 ^= j1;
1775
874
  k1 ^= j1
1776
- # l1 ^= j1 << 16;
1777
875
  l1 ^= (j1 << 16) & 0xffffffff
1778
- # j1 = (k1 >>> 2 ^ l1) & 0x33333333;
1779
- # TODO: check that it is safe to replace >>> with >>
1780
876
  j1 = (k1 >> 2 ^ l1) & 0x33333333
1781
- # l1 ^= j1;
1782
877
  l1 ^= j1
1783
- # k1 ^= j1 << 2;
1784
878
  k1 ^= (j1 << 2) & 0xffffffff
1785
- # j1 = (k1 >>> 8 ^ l1) & 0xff00ff;
1786
879
  j1 = (k1 >> 8 ^ l1) & 0xff00ff
1787
- # l1 ^= j1;
1788
880
  l1 ^= j1
1789
- # k1 ^= j1 << 8;
1790
881
  k1 ^= (j1 << 8) & 0xffffffff
1791
- # k1 = (k1 << 1 | k1 >>> 31 & 1) & -1;
1792
- # TODO: check that it is safe to replace >>> with >>
1793
882
  k1 = (k1 << 1 | k1 >> 31 & 1) & 0xffffffff
1794
- # j1 = (l1 ^ k1) & 0xaaaaaaaa;
1795
883
  j1 = (l1 ^ k1) & 0xaaaaaaaa
1796
- # l1 ^= j1;
1797
884
  l1 ^= j1
1798
- # k1 ^= j1;
1799
885
  k1 ^= j1
1800
- # l1 = (l1 << 1 | l1 >>> 31 & 1) & -1;
1801
- # TODO: check that it is safe to replace >>> with >>
1802
886
  l1 = (l1 << 1 | l1 >> 31 & 1) & 0xffffffff
1803
- # for (int i2 = 0; i2 < 8; i2++) {
1804
887
  for i2 in 0...8
1805
- # j1 = k1 << 28 | k1 >>> 4;
1806
- # TODO: check that it is safe to replace >>> with >>
1807
888
  j1 = (k1 << 28 | k1 >> 4) & 0xffffffff
1808
- # long l2 = 0L;
1809
- # TODO: check if long integeres are processed automatically
1810
889
  l2 = 0
1811
- # l2 = ai1[j2];
1812
890
  l2 = ai1[j2]
1813
- # j1 ^= ai1[j2];
1814
891
  j1 ^= ai1[j2]
1815
- # j2++;
1816
892
  j2 += 1
1817
- # int i1 = bj[j1 & 0x3f];
1818
893
  i1 = Bj[j1 & 0x3f]
1819
- # i1 |= L[j1 >>> 8 & 0x3f];
1820
- # TODO: check if long integeres are processed automatically
1821
894
  i1 |= L[j1 >> 8 & 0x3f]
1822
- # i1 |= P[j1 >>> 16 & 0x3f];
1823
895
  i1 |= P[j1 >> 16 & 0x3f]
1824
- # i1 |= T[j1 >>> 24 & 0x3f];
1825
896
  i1 |= T[j1 >> 24 & 0x3f]
1826
- # j1 = k1 ^ ai1[j2];
1827
897
  j1 = k1 ^ ai1[j2]
1828
- # j2++;
1829
898
  j2 += 1
1830
- # i1 |= bg[j1 & 0x3f];
1831
899
  i1 |= Bg[j1 & 0x3f]
1832
- # i1 |= bm[j1 >>> 8 & 0x3f];
1833
900
  i1 |= Bm[j1 >> 8 & 0x3f]
1834
- # i1 |= N[j1 >>> 16 & 0x3f];
1835
901
  i1 |= N[j1 >> 16 & 0x3f]
1836
- # i1 |= R[j1 >>> 24 & 0x3f];
1837
902
  i1 |= R[j1 >> 24 & 0x3f]
1838
- # l1 ^= i1;
1839
903
  l1 ^= i1
1840
- # j1 = l1 << 28 | l1 >>> 4;
1841
904
  j1 = (l1 << 28 | l1 >> 4) & 0xffffffff
1842
- # j1 ^= ai1[j2];
1843
905
  j1 ^= ai1[j2]
1844
- # j2++;
1845
906
  j2 += 1
1846
- # i1 = bj[j1 & 0x3f];
1847
907
  i1 = Bj[j1 & 0x3f]
1848
- # i1 |= L[j1 >>> 8 & 0x3f];
1849
908
  i1 |= L[j1 >> 8 & 0x3f]
1850
- # i1 |= P[j1 >>> 16 & 0x3f];
1851
909
  i1 |= P[j1 >> 16 & 0x3f]
1852
- # i1 |= T[j1 >>> 24 & 0x3f];
1853
910
  i1 |= T[j1 >> 24 & 0x3f]
1854
- # j1 = l1 ^ ai1[j2];
1855
911
  j1 = l1 ^ ai1[j2]
1856
- # j2++;
1857
912
  j2 += 1
1858
- # i1 |= bg[j1 & 0x3f];
1859
913
  i1 |= Bg[j1 & 0x3f]
1860
- # i1 |= bm[j1 >>> 8 & 0x3f];
1861
914
  i1 |= Bm[j1 >> 8 & 0x3f]
1862
- # i1 |= N[j1 >>> 16 & 0x3f];
1863
915
  i1 |= N[j1 >> 16 & 0x3f]
1864
- # i1 |= R[j1 >>> 24 & 0x3f];
1865
916
  i1 |= R[j1 >> 24 & 0x3f]
1866
- # k1 ^= i1;
1867
917
  k1 ^= i1
1868
- # }
1869
918
  end
1870
- #
1871
- # k1 = k1 << 31 | k1 >>> 1;
1872
919
  k1 = (k1 << 31 | k1 >> 1) & 0xffffffff
1873
- # j1 = (l1 ^ k1) & 0xaaaaaaaa;
1874
920
  j1 = (l1 ^ k1) & 0xaaaaaaaa
1875
- # l1 ^= j1;
1876
921
  l1 ^= j1
1877
- # k1 ^= j1;
1878
922
  k1 ^= j1
1879
- # l1 = l1 << 31 | l1 >>> 1;
1880
923
  l1 = l1 << 31 | l1 >> 1
1881
- # j1 = (l1 >>> 8 ^ k1) & 0xff00ff;
1882
924
  j1 = (l1 >> 8 ^ k1) & 0xff00ff
1883
- # k1 ^= j1;
1884
925
  k1 ^= j1
1885
- # l1 ^= j1 << 8;
1886
926
  l1 ^= (j1 << 8) & 0xffffffff
1887
- # j1 = (l1 >>> 2 ^ k1) & 0x33333333;
1888
927
  j1 = (l1 >> 2 ^ k1) & 0x33333333
1889
- # k1 ^= j1;
1890
928
  k1 ^= j1
1891
- # l1 ^= j1 << 2;
1892
929
  l1 ^= (j1 << 2) & 0xffffffff
1893
- # j1 = (k1 >>> 16 ^ l1) & 0xffff;
1894
930
  j1 = (k1 >> 16 ^ l1) & 0xffff
1895
- # l1 ^= j1;
1896
931
  l1 ^= j1
1897
- # k1 ^= j1 << 16;
1898
932
  k1 ^= (j1 << 16) & 0xffffffff
1899
- # j1 = (k1 >>> 4 ^ l1) & 0xf0f0f0f;
1900
933
  j1 = (k1 >> 4 ^ l1) & 0xf0f0f0f
1901
- # l1 ^= j1;
1902
934
  l1 ^= j1
1903
- # k1 ^= j1 << 4;
1904
935
  k1 ^= (j1 << 4) & 0xffffffff
1905
- # ai[0] = k1;
1906
936
  ai[0] = k1
1907
- # ai[1] = l1;
1908
937
  ai[1] = l1
1909
- # }
1910
938
  end
1911
939
 
1912
- # private static byte[] G(byte abyte0[], byte abyte1[]) {
1913
940
  def g_(abyte0, abyte1)
1914
- # if (abyte0.length < 32) {
1915
- # return null;
1916
- # }
1917
941
  if (abyte0.length < 32)
1918
942
  return nil
1919
943
  end
1920
- # byte abyte3[] = new byte[8];
1921
944
  abyte3 = "\0"*8
1922
- # byte abyte4[] = new byte[8];
1923
945
  abyte4 = "\0"*8
1924
- # byte abyte5[] = new byte[8];
1925
- abyte5 = "\0"*8
1926
- # byte abyte2[] = new byte[8];
946
+ abyte5 = "\0"*8
1927
947
  abyte2 = "\0"*8
1928
- # System.arraycopy(abyte0, 0, abyte3, 0, 8);
1929
948
  abyte3[0, 8] = abyte0[0, 8]
1930
- # System.arraycopy(abyte0, 8, abyte4, 0, 8);
1931
949
  abyte4[0, 8] = abyte0[8, 8]
1932
- # System.arraycopy(abyte0, 16, abyte5, 0, 8);
1933
950
  abyte5[0, 8] = abyte0[16, 8]
1934
- # System.arraycopy(abyte0, 24, abyte2, 0, 8);
1935
951
  abyte2[0, 8] = abyte0[24, 0]
1936
- # int ai[] = l(abyte3, true);
1937
952
  ai = l(abyte3, true)
1938
- # int ai1[] = l(abyte4, false);
1939
953
  ai1 = l(abyte4, false)
1940
- # int ai2[] = l(abyte5, true);
1941
954
  ai2 = l(abyte5, true)
1942
- # int i1 = abyte1.length % 8;
1943
955
  i1 = abyte1.length % 8
1944
- # byte byte0 = (byte) (8 - i1);
1945
956
  byte0 = (8 - i1)
1946
- # byte abyte6[] = new byte[abyte1.length + byte0];
1947
957
  abyte6 = "\0"*(abyte1.length + byte0)
1948
- # int j1 = abyte6.length / 8 - 1;
1949
958
  j1 = abyte6.length / 8 - 1
1950
- # int k1 = 8 * j1;
1951
959
  k1 = 8 * j1
1952
- # byte abyte7[] = new byte[8];
1953
960
  abyte7 = "\0"*8
1954
- # System.arraycopy(abyte1, k1, abyte7, 0, i1);
1955
961
  abyte7[0, i1] = abyte1[k1, i1]
1956
- # for (int l1 = i1; l1 < 8; l1++) {
1957
- # abyte7[l1] = byte0;
1958
- #
1959
- # }
1960
962
  for l1 in i1...8
1961
963
  abyte7[l1] = byte0
1962
964
  end
1963
- # int i2 = 0;
1964
965
  i2 = 0
1965
- # for (int j2 = 0; i2 < j1; j2 += 8) {
1966
- # q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true);
1967
- # i2++;
1968
- # }
1969
966
  j2 = 0
1970
967
  while (i2 < j1)
1971
968
  q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true)
1972
969
  i2 += 1
1973
970
  j2 += 8
1974
971
  end
1975
- #
1976
- # q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true);
1977
972
  q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true)
1978
- # return abyte6;
1979
973
  return abyte6
1980
- # }
1981
974
  end
1982
975
 
1983
- # private static void H(int ai[]) {
1984
- # ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999;
1985
- # ai[2] = j(ai[1], 30);
1986
- # }
1987
976
  def h_(ai)
1988
977
  ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999
1989
978
  ai[2] = j(ai[1], 30)
1990
979
  end
1991
980
 
1992
- # private static void I(int ai[]) {
1993
- # ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1;
1994
- # ai[2] = j(ai[1], 30);
1995
- # }
1996
981
  def i_(ai)
1997
982
  ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1
1998
983
  ai[2] = j(ai[1], 30)
@@ -2164,7 +1149,5 @@ module OracleEbsAuthentication
2164
1149
  0x20004010, 0,
2165
1150
  0x20404000, 0x20000000, 0x400010, 0x20004010
2166
1151
  ]
2167
-
2168
1152
  end
2169
-
2170
1153
  end