Merge pull request #4 from ayunami2000/encryption
add encryption (means you can join real 1.5.2 servers!!)
This commit is contained in:
commit
b3892841f0
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
|
@ -78,6 +78,6 @@ teavm {
|
|||
/** Add name of configurations here where to look for jarfiles. */
|
||||
includeJarsFrom = [];
|
||||
|
||||
/** By default teavmc taskd epends on javaCompile task, unless this varaibale is true. */
|
||||
/** By default teavmc task depends on javaCompile task, unless this variable is true. */
|
||||
skipJavaCompile = false;
|
||||
}
|
||||
|
|
161
javascript/asn1-parser.js
Normal file
161
javascript/asn1-parser.js
Normal file
|
@ -0,0 +1,161 @@
|
|||
// Copyright 2018 AJ ONeal. All rights reserved
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
;(function (exports) {
|
||||
'use strict';
|
||||
|
||||
if (!exports.ASN1) { exports.ASN1 = {}; }
|
||||
if (!exports.Enc) { exports.Enc = {}; }
|
||||
if (!exports.PEM) { exports.PEM = {}; }
|
||||
|
||||
var ASN1 = exports.ASN1;
|
||||
var Enc = exports.Enc;
|
||||
var PEM = exports.PEM;
|
||||
|
||||
//
|
||||
// Parser
|
||||
//
|
||||
|
||||
// Although I've only seen 9 max in https certificates themselves,
|
||||
// but each domain list could have up to 100
|
||||
ASN1.ELOOPN = 102;
|
||||
ASN1.ELOOP = "uASN1.js Error: iterated over " + ASN1.ELOOPN + "+ elements (probably a malformed file)";
|
||||
// I've seen https certificates go 29 deep
|
||||
ASN1.EDEEPN = 60;
|
||||
ASN1.EDEEP = "uASN1.js Error: element nested " + ASN1.EDEEPN + "+ layers deep (probably a malformed file)";
|
||||
// Container Types are Sequence 0x30, Container Array? (0xA0, 0xA1)
|
||||
// Value Types are Boolean 0x01, Integer 0x02, Null 0x05, Object ID 0x06, String 0x0C, 0x16, 0x13, 0x1e Value Array? (0x82)
|
||||
// Bit String (0x03) and Octet String (0x04) may be values or containers
|
||||
// Sometimes Bit String is used as a container (RSA Pub Spki)
|
||||
ASN1.CTYPES = [ 0x30, 0x31, 0xa0, 0xa1 ];
|
||||
ASN1.VTYPES = [ 0x01, 0x02, 0x05, 0x06, 0x0c, 0x82 ];
|
||||
ASN1.parse = function parseAsn1Helper(buf) {
|
||||
//var ws = ' ';
|
||||
function parseAsn1(buf, depth, eager) {
|
||||
if (depth.length >= ASN1.EDEEPN) { throw new Error(ASN1.EDEEP); }
|
||||
|
||||
var index = 2; // we know, at minimum, data starts after type (0) and lengthSize (1)
|
||||
var asn1 = { type: buf[0], lengthSize: 0, length: buf[1] };
|
||||
var child;
|
||||
var iters = 0;
|
||||
var adjust = 0;
|
||||
var adjustedLen;
|
||||
|
||||
// Determine how many bytes the length uses, and what it is
|
||||
if (0x80 & asn1.length) {
|
||||
asn1.lengthSize = 0x7f & asn1.length;
|
||||
// I think that buf->hex->int solves the problem of Endianness... not sure
|
||||
asn1.length = parseInt(Enc.bufToHex(buf.slice(index, index + asn1.lengthSize)), 16);
|
||||
index += asn1.lengthSize;
|
||||
}
|
||||
|
||||
// High-order bit Integers have a leading 0x00 to signify that they are positive.
|
||||
// Bit Streams use the first byte to signify padding, which x.509 doesn't use.
|
||||
if (0x00 === buf[index] && (0x02 === asn1.type || 0x03 === asn1.type)) {
|
||||
// However, 0x00 on its own is a valid number
|
||||
if (asn1.length > 1) {
|
||||
index += 1;
|
||||
adjust = -1;
|
||||
}
|
||||
}
|
||||
adjustedLen = asn1.length + adjust;
|
||||
|
||||
//console.warn(depth.join(ws) + '0x' + Enc.numToHex(asn1.type), index, 'len:', asn1.length, asn1);
|
||||
|
||||
function parseChildren(eager) {
|
||||
asn1.children = [];
|
||||
//console.warn('1 len:', (2 + asn1.lengthSize + asn1.length), 'idx:', index, 'clen:', 0);
|
||||
while (iters < ASN1.ELOOPN && index < (2 + asn1.length + asn1.lengthSize)) {
|
||||
iters += 1;
|
||||
depth.length += 1;
|
||||
child = parseAsn1(buf.slice(index, index + adjustedLen), depth, eager);
|
||||
depth.length -= 1;
|
||||
// The numbers don't match up exactly and I don't remember why...
|
||||
// probably something with adjustedLen or some such, but the tests pass
|
||||
index += (2 + child.lengthSize + child.length);
|
||||
//console.warn('2 len:', (2 + asn1.lengthSize + asn1.length), 'idx:', index, 'clen:', (2 + child.lengthSize + child.length));
|
||||
if (index > (2 + asn1.lengthSize + asn1.length)) {
|
||||
if (!eager) { console.error(JSON.stringify(asn1, ASN1._replacer, 2)); }
|
||||
throw new Error("Parse error: child value length (" + child.length
|
||||
+ ") is greater than remaining parent length (" + (asn1.length - index)
|
||||
+ " = " + asn1.length + " - " + index + ")");
|
||||
}
|
||||
asn1.children.push(child);
|
||||
//console.warn(depth.join(ws) + '0x' + Enc.numToHex(asn1.type), index, 'len:', asn1.length, asn1);
|
||||
}
|
||||
if (index !== (2 + asn1.lengthSize + asn1.length)) {
|
||||
//console.warn('index:', index, 'length:', (2 + asn1.lengthSize + asn1.length));
|
||||
throw new Error("premature end-of-file");
|
||||
}
|
||||
if (iters >= ASN1.ELOOPN) { throw new Error(ASN1.ELOOP); }
|
||||
|
||||
delete asn1.value;
|
||||
return asn1;
|
||||
}
|
||||
|
||||
// Recurse into types that are _always_ containers
|
||||
if (-1 !== ASN1.CTYPES.indexOf(asn1.type)) { return parseChildren(eager); }
|
||||
|
||||
// Return types that are _always_ values
|
||||
asn1.value = buf.slice(index, index + adjustedLen);
|
||||
if (-1 !== ASN1.VTYPES.indexOf(asn1.type)) { return asn1; }
|
||||
|
||||
// For ambigious / unknown types, recurse and return on failure
|
||||
// (and return child array size to zero)
|
||||
try { return parseChildren(true); }
|
||||
catch(e) { asn1.children.length = 0; return asn1; }
|
||||
}
|
||||
|
||||
var asn1 = parseAsn1(buf, []);
|
||||
var len = buf.byteLength || buf.length;
|
||||
if (len !== 2 + asn1.lengthSize + asn1.length) {
|
||||
throw new Error("Length of buffer does not match length of ASN.1 sequence.");
|
||||
}
|
||||
return asn1;
|
||||
};
|
||||
ASN1._replacer = function (k, v) {
|
||||
if ('type' === k) { return '0x' + Enc.numToHex(v); }
|
||||
if (v && 'value' === k) { return '0x' + Enc.bufToHex(v.data || v); }
|
||||
return v;
|
||||
};
|
||||
|
||||
// don't replace the full parseBlock, if it exists
|
||||
PEM.parseBlock = PEM.parseBlock || function (str) {
|
||||
var der = str.split(/\n/).filter(function (line) {
|
||||
return !/-----/.test(line);
|
||||
}).join('');
|
||||
return { der: Enc.base64ToBuf(der) };
|
||||
};
|
||||
|
||||
Enc.base64ToBuf = function (b64) {
|
||||
return Enc.binToBuf(atob(b64));
|
||||
};
|
||||
Enc.binToBuf = function (bin) {
|
||||
var arr = bin.split('').map(function (ch) {
|
||||
return ch.charCodeAt(0);
|
||||
});
|
||||
return 'undefined' !== typeof Uint8Array ? new Uint8Array(arr) : arr;
|
||||
};
|
||||
Enc.bufToHex = function (u8) {
|
||||
var hex = [];
|
||||
var i, h;
|
||||
var len = (u8.byteLength || u8.length);
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
h = u8[i].toString(16);
|
||||
if (h.length % 2) { h = '0' + h; }
|
||||
hex.push(h);
|
||||
}
|
||||
|
||||
return hex.join('').toLowerCase();
|
||||
};
|
||||
Enc.numToHex = function (d) {
|
||||
d = d.toString(16);
|
||||
if (d.length % 2) {
|
||||
return '0' + d;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
|
||||
}('undefined' !== typeof window ? window : module.exports));
|
39163
javascript/classes.js
39163
javascript/classes.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,19 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>eagler</title>
|
||||
|
||||
<script type="text/javascript" src="jsbn/jsbn.js"></script>
|
||||
<script type="text/javascript" src="jsbn/jsbn2.js"></script>
|
||||
<script type="text/javascript" src="jsbn/base64.js"></script>
|
||||
<script type="text/javascript" src="jsbn/prng4.js"></script>
|
||||
<script type="text/javascript" src="jsbn/rng.js"></script>
|
||||
<script type="text/javascript" src="jsbn/rsa.js"></script>
|
||||
<script type="text/javascript" src="jsbn/rsa2.js"></script>
|
||||
|
||||
<script type="text/javascript" src="asn1-parser.js"></script>
|
||||
|
||||
<script type="text/javascript" src="classes.js"></script>
|
||||
<!--script src="https://unpkg.com/@peculiar/x509"></script-->
|
||||
<script type="text/javascript">
|
||||
window.addEventListener("load", function(){ window.minecraftOpts = [
|
||||
"game_frame","assets.epk",
|
||||
|
|
71
javascript/jsbn/base64.js
Normal file
71
javascript/jsbn/base64.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var b64padchar="=";
|
||||
|
||||
function hex2b64(h) {
|
||||
var i;
|
||||
var c;
|
||||
var ret = "";
|
||||
for(i = 0; i+3 <= h.length; i+=3) {
|
||||
c = parseInt(h.substring(i,i+3),16);
|
||||
ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
|
||||
}
|
||||
if(i+1 == h.length) {
|
||||
c = parseInt(h.substring(i,i+1),16);
|
||||
ret += b64map.charAt(c << 2);
|
||||
}
|
||||
else if(i+2 == h.length) {
|
||||
c = parseInt(h.substring(i,i+2),16);
|
||||
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
|
||||
}
|
||||
while((ret.length & 3) > 0) ret += b64padchar;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// convert a base64 string to hex
|
||||
function b64tohex(s) {
|
||||
var ret = ""
|
||||
var i;
|
||||
var k = 0; // b64 state, 0-3
|
||||
var slop;
|
||||
for(i = 0; i < s.length; ++i) {
|
||||
if(s.charAt(i) == b64padchar) break;
|
||||
v = b64map.indexOf(s.charAt(i));
|
||||
if(v < 0) continue;
|
||||
if(k == 0) {
|
||||
ret += int2char(v >> 2);
|
||||
slop = v & 3;
|
||||
k = 1;
|
||||
}
|
||||
else if(k == 1) {
|
||||
ret += int2char((slop << 2) | (v >> 4));
|
||||
slop = v & 0xf;
|
||||
k = 2;
|
||||
}
|
||||
else if(k == 2) {
|
||||
ret += int2char(slop);
|
||||
ret += int2char(v >> 2);
|
||||
slop = v & 3;
|
||||
k = 3;
|
||||
}
|
||||
else {
|
||||
ret += int2char((slop << 2) | (v >> 4));
|
||||
ret += int2char(v & 0xf);
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if(k == 1)
|
||||
ret += int2char(slop << 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// convert a base64 string to a byte/number array
|
||||
function b64toBA(s) {
|
||||
//piggyback on b64tohex for now, optimize later
|
||||
var h = b64tohex(s);
|
||||
var i;
|
||||
var a = new Array();
|
||||
for(i = 0; 2*i < h.length; ++i) {
|
||||
a[i] = parseInt(h.substring(2*i,2*i+2),16);
|
||||
}
|
||||
return a;
|
||||
}
|
559
javascript/jsbn/jsbn.js
Normal file
559
javascript/jsbn/jsbn.js
Normal file
|
@ -0,0 +1,559 @@
|
|||
// Copyright (c) 2005 Tom Wu
|
||||
// All Rights Reserved.
|
||||
// See "LICENSE" for details.
|
||||
|
||||
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||||
|
||||
// Bits per digit
|
||||
var dbits;
|
||||
|
||||
// JavaScript engine analysis
|
||||
var canary = 0xdeadbeefcafe;
|
||||
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||||
|
||||
// (public) Constructor
|
||||
function BigInteger(a,b,c) {
|
||||
if(a != null)
|
||||
if("number" == typeof a) this.fromNumber(a,b,c);
|
||||
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||||
else this.fromString(a,b);
|
||||
}
|
||||
|
||||
// return new, unset BigInteger
|
||||
function nbi() { return new BigInteger(null); }
|
||||
|
||||
// am: Compute w_j += (x*this_i), propagate carries,
|
||||
// c is initial carry, returns final carry.
|
||||
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||||
// We need to select the fastest one that works in this environment.
|
||||
|
||||
// am1: use a single mult and divide to get the high bits,
|
||||
// max digit bits should be 26 because
|
||||
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||||
function am1(i,x,w,j,c,n) {
|
||||
while(--n >= 0) {
|
||||
var v = x*this[i++]+w[j]+c;
|
||||
c = Math.floor(v/0x4000000);
|
||||
w[j++] = v&0x3ffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// am2 avoids a big mult-and-extract completely.
|
||||
// Max digit bits should be <= 30 because we do bitwise ops
|
||||
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||||
function am2(i,x,w,j,c,n) {
|
||||
var xl = x&0x7fff, xh = x>>15;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x7fff;
|
||||
var h = this[i++]>>15;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||||
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||||
w[j++] = l&0x3fffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// Alternately, set max digit bits to 28 since some
|
||||
// browsers slow down when dealing with 32-bit numbers.
|
||||
function am3(i,x,w,j,c,n) {
|
||||
var xl = x&0x3fff, xh = x>>14;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x3fff;
|
||||
var h = this[i++]>>14;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||||
c = (l>>28)+(m>>14)+xh*h;
|
||||
w[j++] = l&0xfffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||
BigInteger.prototype.am = am2;
|
||||
dbits = 30;
|
||||
}
|
||||
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||
BigInteger.prototype.am = am1;
|
||||
dbits = 26;
|
||||
}
|
||||
else { // Mozilla/Netscape seems to prefer am3
|
||||
BigInteger.prototype.am = am3;
|
||||
dbits = 28;
|
||||
}
|
||||
|
||||
BigInteger.prototype.DB = dbits;
|
||||
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||
BigInteger.prototype.DV = (1<<dbits);
|
||||
|
||||
var BI_FP = 52;
|
||||
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||||
BigInteger.prototype.F1 = BI_FP-dbits;
|
||||
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||||
|
||||
// Digit conversions
|
||||
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
var BI_RC = new Array();
|
||||
var rr,vv;
|
||||
rr = "0".charCodeAt(0);
|
||||
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "a".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "A".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
|
||||
function int2char(n) { return BI_RM.charAt(n); }
|
||||
function intAt(s,i) {
|
||||
var c = BI_RC[s.charCodeAt(i)];
|
||||
return (c==null)?-1:c;
|
||||
}
|
||||
|
||||
// (protected) copy this to r
|
||||
function bnpCopyTo(r) {
|
||||
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||||
r.t = this.t;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) set from integer value x, -DV <= x < DV
|
||||
function bnpFromInt(x) {
|
||||
this.t = 1;
|
||||
this.s = (x<0)?-1:0;
|
||||
if(x > 0) this[0] = x;
|
||||
else if(x < -1) this[0] = x+this.DV;
|
||||
else this.t = 0;
|
||||
}
|
||||
|
||||
// return bigint initialized to value
|
||||
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||||
|
||||
// (protected) set from string and radix
|
||||
function bnpFromString(s,b) {
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 256) k = 8; // byte array
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else { this.fromRadix(s,b); return; }
|
||||
this.t = 0;
|
||||
this.s = 0;
|
||||
var i = s.length, mi = false, sh = 0;
|
||||
while(--i >= 0) {
|
||||
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||||
if(x < 0) {
|
||||
if(s.charAt(i) == "-") mi = true;
|
||||
continue;
|
||||
}
|
||||
mi = false;
|
||||
if(sh == 0)
|
||||
this[this.t++] = x;
|
||||
else if(sh+k > this.DB) {
|
||||
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||||
this[this.t++] = (x>>(this.DB-sh));
|
||||
}
|
||||
else
|
||||
this[this.t-1] |= x<<sh;
|
||||
sh += k;
|
||||
if(sh >= this.DB) sh -= this.DB;
|
||||
}
|
||||
if(k == 8 && (s[0]&0x80) != 0) {
|
||||
this.s = -1;
|
||||
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||||
}
|
||||
this.clamp();
|
||||
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||
}
|
||||
|
||||
// (protected) clamp off excess high words
|
||||
function bnpClamp() {
|
||||
var c = this.s&this.DM;
|
||||
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||||
}
|
||||
|
||||
// (public) return string representation in given radix
|
||||
function bnToString(b) {
|
||||
if(this.s < 0) return "-"+this.negate().toString(b);
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else return this.toRadix(b);
|
||||
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||||
var p = this.DB-(i*this.DB)%k;
|
||||
if(i-- > 0) {
|
||||
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||||
while(i >= 0) {
|
||||
if(p < k) {
|
||||
d = (this[i]&((1<<p)-1))<<(k-p);
|
||||
d |= this[--i]>>(p+=this.DB-k);
|
||||
}
|
||||
else {
|
||||
d = (this[i]>>(p-=k))&km;
|
||||
if(p <= 0) { p += this.DB; --i; }
|
||||
}
|
||||
if(d > 0) m = true;
|
||||
if(m) r += int2char(d);
|
||||
}
|
||||
}
|
||||
return m?r:"0";
|
||||
}
|
||||
|
||||
// (public) -this
|
||||
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||||
|
||||
// (public) |this|
|
||||
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||||
|
||||
// (public) return + if this > a, - if this < a, 0 if equal
|
||||
function bnCompareTo(a) {
|
||||
var r = this.s-a.s;
|
||||
if(r != 0) return r;
|
||||
var i = this.t;
|
||||
r = i-a.t;
|
||||
if(r != 0) return (this.s<0)?-r:r;
|
||||
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// returns bit length of the integer x
|
||||
function nbits(x) {
|
||||
var r = 1, t;
|
||||
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||||
if((t=x>>8) != 0) { x = t; r += 8; }
|
||||
if((t=x>>4) != 0) { x = t; r += 4; }
|
||||
if((t=x>>2) != 0) { x = t; r += 2; }
|
||||
if((t=x>>1) != 0) { x = t; r += 1; }
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) return the number of bits in "this"
|
||||
function bnBitLength() {
|
||||
if(this.t <= 0) return 0;
|
||||
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||||
}
|
||||
|
||||
// (protected) r = this << n*DB
|
||||
function bnpDLShiftTo(n,r) {
|
||||
var i;
|
||||
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||||
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||||
r.t = this.t+n;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this >> n*DB
|
||||
function bnpDRShiftTo(n,r) {
|
||||
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||||
r.t = Math.max(this.t-n,0);
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this << n
|
||||
function bnpLShiftTo(n,r) {
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<cbs)-1;
|
||||
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||||
for(i = this.t-1; i >= 0; --i) {
|
||||
r[i+ds+1] = (this[i]>>cbs)|c;
|
||||
c = (this[i]&bm)<<bs;
|
||||
}
|
||||
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||||
r[ds] = c;
|
||||
r.t = this.t+ds+1;
|
||||
r.s = this.s;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this >> n
|
||||
function bnpRShiftTo(n,r) {
|
||||
r.s = this.s;
|
||||
var ds = Math.floor(n/this.DB);
|
||||
if(ds >= this.t) { r.t = 0; return; }
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<bs)-1;
|
||||
r[0] = this[ds]>>bs;
|
||||
for(var i = ds+1; i < this.t; ++i) {
|
||||
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||||
r[i-ds] = this[i]>>bs;
|
||||
}
|
||||
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||||
r.t = this.t-ds;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this - a
|
||||
function bnpSubTo(a,r) {
|
||||
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||
while(i < m) {
|
||||
c += this[i]-a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
if(a.t < this.t) {
|
||||
c -= a.s;
|
||||
while(i < this.t) {
|
||||
c += this[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += this.s;
|
||||
}
|
||||
else {
|
||||
c += this.s;
|
||||
while(i < a.t) {
|
||||
c -= a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c -= a.s;
|
||||
}
|
||||
r.s = (c<0)?-1:0;
|
||||
if(c < -1) r[i++] = this.DV+c;
|
||||
else if(c > 0) r[i++] = c;
|
||||
r.t = i;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyTo(a,r) {
|
||||
var x = this.abs(), y = a.abs();
|
||||
var i = x.t;
|
||||
r.t = i+y.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (protected) r = this^2, r != this (HAC 14.16)
|
||||
function bnpSquareTo(r) {
|
||||
var x = this.abs();
|
||||
var i = r.t = 2*x.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < x.t-1; ++i) {
|
||||
var c = x.am(i,x[i],r,2*i,0,1);
|
||||
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||||
r[i+x.t] -= x.DV;
|
||||
r[i+x.t+1] = 1;
|
||||
}
|
||||
}
|
||||
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||
// r != q, this != m. q or r may be null.
|
||||
function bnpDivRemTo(m,q,r) {
|
||||
var pm = m.abs();
|
||||
if(pm.t <= 0) return;
|
||||
var pt = this.abs();
|
||||
if(pt.t < pm.t) {
|
||||
if(q != null) q.fromInt(0);
|
||||
if(r != null) this.copyTo(r);
|
||||
return;
|
||||
}
|
||||
if(r == null) r = nbi();
|
||||
var y = nbi(), ts = this.s, ms = m.s;
|
||||
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||||
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||||
else { pm.copyTo(y); pt.copyTo(r); }
|
||||
var ys = y.t;
|
||||
var y0 = y[ys-1];
|
||||
if(y0 == 0) return;
|
||||
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||||
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||||
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||||
y.dlShiftTo(j,t);
|
||||
if(r.compareTo(t) >= 0) {
|
||||
r[r.t++] = 1;
|
||||
r.subTo(t,r);
|
||||
}
|
||||
BigInteger.ONE.dlShiftTo(ys,t);
|
||||
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||||
while(y.t < ys) y[y.t++] = 0;
|
||||
while(--j >= 0) {
|
||||
// Estimate quotient digit
|
||||
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||||
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||||
y.dlShiftTo(j,t);
|
||||
r.subTo(t,r);
|
||||
while(r[i] < --qd) r.subTo(t,r);
|
||||
}
|
||||
}
|
||||
if(q != null) {
|
||||
r.drShiftTo(ys,q);
|
||||
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||||
}
|
||||
r.t = ys;
|
||||
r.clamp();
|
||||
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||||
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (public) this mod a
|
||||
function bnMod(a) {
|
||||
var r = nbi();
|
||||
this.abs().divRemTo(a,null,r);
|
||||
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Modular reduction using "classic" algorithm
|
||||
function Classic(m) { this.m = m; }
|
||||
function cConvert(x) {
|
||||
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||||
else return x;
|
||||
}
|
||||
function cRevert(x) { return x; }
|
||||
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||||
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
Classic.prototype.convert = cConvert;
|
||||
Classic.prototype.revert = cRevert;
|
||||
Classic.prototype.reduce = cReduce;
|
||||
Classic.prototype.mulTo = cMulTo;
|
||||
Classic.prototype.sqrTo = cSqrTo;
|
||||
|
||||
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||
// justification:
|
||||
// xy == 1 (mod m)
|
||||
// xy = 1+km
|
||||
// xy(2-xy) = (1+km)(1-km)
|
||||
// x[y(2-xy)] = 1-k^2m^2
|
||||
// x[y(2-xy)] == 1 (mod m^2)
|
||||
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||||
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||||
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||||
function bnpInvDigit() {
|
||||
if(this.t < 1) return 0;
|
||||
var x = this[0];
|
||||
if((x&1) == 0) return 0;
|
||||
var y = x&3; // y == 1/x mod 2^2
|
||||
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||||
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||||
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||||
// last step - calculate inverse mod DV directly;
|
||||
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||||
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||||
// we really want the negative inverse, and -DV < y < DV
|
||||
return (y>0)?this.DV-y:-y;
|
||||
}
|
||||
|
||||
// Montgomery reduction
|
||||
function Montgomery(m) {
|
||||
this.m = m;
|
||||
this.mp = m.invDigit();
|
||||
this.mpl = this.mp&0x7fff;
|
||||
this.mph = this.mp>>15;
|
||||
this.um = (1<<(m.DB-15))-1;
|
||||
this.mt2 = 2*m.t;
|
||||
}
|
||||
|
||||
// xR mod m
|
||||
function montConvert(x) {
|
||||
var r = nbi();
|
||||
x.abs().dlShiftTo(this.m.t,r);
|
||||
r.divRemTo(this.m,null,r);
|
||||
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x/R mod m
|
||||
function montRevert(x) {
|
||||
var r = nbi();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x = x/R mod m (HAC 14.32)
|
||||
function montReduce(x) {
|
||||
while(x.t <= this.mt2) // pad x so am has enough room later
|
||||
x[x.t++] = 0;
|
||||
for(var i = 0; i < this.m.t; ++i) {
|
||||
// faster way of calculating u0 = x[i]*mp mod DV
|
||||
var j = x[i]&0x7fff;
|
||||
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||||
// use am to combine the multiply-shift-add into one call
|
||||
j = i+this.m.t;
|
||||
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||
// propagate carry
|
||||
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||||
}
|
||||
x.clamp();
|
||||
x.drShiftTo(this.m.t,x);
|
||||
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||
}
|
||||
|
||||
// r = "x^2/R mod m"; x != r
|
||||
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
// r = "xy/R mod m"; x,y != r
|
||||
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
|
||||
Montgomery.prototype.convert = montConvert;
|
||||
Montgomery.prototype.revert = montRevert;
|
||||
Montgomery.prototype.reduce = montReduce;
|
||||
Montgomery.prototype.mulTo = montMulTo;
|
||||
Montgomery.prototype.sqrTo = montSqrTo;
|
||||
|
||||
// (protected) true iff this is even
|
||||
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||||
|
||||
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||
function bnpExp(e,z) {
|
||||
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||||
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||||
g.copyTo(r);
|
||||
while(--i >= 0) {
|
||||
z.sqrTo(r,r2);
|
||||
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||||
else { var t = r; r = r2; r2 = t; }
|
||||
}
|
||||
return z.revert(r);
|
||||
}
|
||||
|
||||
// (public) this^e % m, 0 <= e < 2^32
|
||||
function bnModPowInt(e,m) {
|
||||
var z;
|
||||
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||||
return this.exp(e,z);
|
||||
}
|
||||
|
||||
// protected
|
||||
BigInteger.prototype.copyTo = bnpCopyTo;
|
||||
BigInteger.prototype.fromInt = bnpFromInt;
|
||||
BigInteger.prototype.fromString = bnpFromString;
|
||||
BigInteger.prototype.clamp = bnpClamp;
|
||||
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||||
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||||
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||||
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||||
BigInteger.prototype.subTo = bnpSubTo;
|
||||
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||||
BigInteger.prototype.squareTo = bnpSquareTo;
|
||||
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||||
BigInteger.prototype.invDigit = bnpInvDigit;
|
||||
BigInteger.prototype.isEven = bnpIsEven;
|
||||
BigInteger.prototype.exp = bnpExp;
|
||||
|
||||
// public
|
||||
BigInteger.prototype.toString = bnToString;
|
||||
BigInteger.prototype.negate = bnNegate;
|
||||
BigInteger.prototype.abs = bnAbs;
|
||||
BigInteger.prototype.compareTo = bnCompareTo;
|
||||
BigInteger.prototype.bitLength = bnBitLength;
|
||||
BigInteger.prototype.mod = bnMod;
|
||||
BigInteger.prototype.modPowInt = bnModPowInt;
|
||||
|
||||
// "constants"
|
||||
BigInteger.ZERO = nbv(0);
|
||||
BigInteger.ONE = nbv(1);
|
656
javascript/jsbn/jsbn2.js
Normal file
656
javascript/jsbn/jsbn2.js
Normal file
|
@ -0,0 +1,656 @@
|
|||
// Copyright (c) 2005-2009 Tom Wu
|
||||
// All Rights Reserved.
|
||||
// See "LICENSE" for details.
|
||||
|
||||
// Extended JavaScript BN functions, required for RSA private ops.
|
||||
|
||||
// Version 1.1: new BigInteger("0", 10) returns "proper" zero
|
||||
// Version 1.2: square() API, isProbablePrime fix
|
||||
|
||||
// (public)
|
||||
function bnClone() { var r = nbi(); this.copyTo(r); return r; }
|
||||
|
||||
// (public) return value as integer
|
||||
function bnIntValue() {
|
||||
if(this.s < 0) {
|
||||
if(this.t == 1) return this[0]-this.DV;
|
||||
else if(this.t == 0) return -1;
|
||||
}
|
||||
else if(this.t == 1) return this[0];
|
||||
else if(this.t == 0) return 0;
|
||||
// assumes 16 < DB < 32
|
||||
return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
|
||||
}
|
||||
|
||||
// (public) return value as byte
|
||||
function bnByteValue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
|
||||
|
||||
// (public) return value as short (assumes DB>=16)
|
||||
function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
|
||||
|
||||
// (protected) return x s.t. r^x < DV
|
||||
function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
|
||||
|
||||
// (public) 0 if this == 0, 1 if this > 0
|
||||
function bnSigNum() {
|
||||
if(this.s < 0) return -1;
|
||||
else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
// (protected) convert to radix string
|
||||
function bnpToRadix(b) {
|
||||
if(b == null) b = 10;
|
||||
if(this.signum() == 0 || b < 2 || b > 36) return "0";
|
||||
var cs = this.chunkSize(b);
|
||||
var a = Math.pow(b,cs);
|
||||
var d = nbv(a), y = nbi(), z = nbi(), r = "";
|
||||
this.divRemTo(d,y,z);
|
||||
while(y.signum() > 0) {
|
||||
r = (a+z.intValue()).toString(b).substr(1) + r;
|
||||
y.divRemTo(d,y,z);
|
||||
}
|
||||
return z.intValue().toString(b) + r;
|
||||
}
|
||||
|
||||
// (protected) convert from radix string
|
||||
function bnpFromRadix(s,b) {
|
||||
this.fromInt(0);
|
||||
if(b == null) b = 10;
|
||||
var cs = this.chunkSize(b);
|
||||
var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
|
||||
for(var i = 0; i < s.length; ++i) {
|
||||
var x = intAt(s,i);
|
||||
if(x < 0) {
|
||||
if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
|
||||
continue;
|
||||
}
|
||||
w = b*w+x;
|
||||
if(++j >= cs) {
|
||||
this.dMultiply(d);
|
||||
this.dAddOffset(w,0);
|
||||
j = 0;
|
||||
w = 0;
|
||||
}
|
||||
}
|
||||
if(j > 0) {
|
||||
this.dMultiply(Math.pow(b,j));
|
||||
this.dAddOffset(w,0);
|
||||
}
|
||||
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||
}
|
||||
|
||||
// (protected) alternate constructor
|
||||
function bnpFromNumber(a,b,c) {
|
||||
if("number" == typeof b) {
|
||||
// new BigInteger(int,int,RNG)
|
||||
if(a < 2) this.fromInt(1);
|
||||
else {
|
||||
this.fromNumber(a,c);
|
||||
if(!this.testBit(a-1)) // force MSB set
|
||||
this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
|
||||
if(this.isEven()) this.dAddOffset(1,0); // force odd
|
||||
while(!this.isProbablePrime(b)) {
|
||||
this.dAddOffset(2,0);
|
||||
if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// new BigInteger(int,RNG)
|
||||
var x = new Array(), t = a&7;
|
||||
x.length = (a>>3)+1;
|
||||
b.nextBytes(x);
|
||||
if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
|
||||
this.fromString(x,256);
|
||||
}
|
||||
}
|
||||
|
||||
// (public) convert to bigendian byte array
|
||||
function bnToByteArray() {
|
||||
var i = this.t, r = new Array();
|
||||
r[0] = this.s;
|
||||
var p = this.DB-(i*this.DB)%8, d, k = 0;
|
||||
if(i-- > 0) {
|
||||
if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p)
|
||||
r[k++] = d|(this.s<<(this.DB-p));
|
||||
while(i >= 0) {
|
||||
if(p < 8) {
|
||||
d = (this[i]&((1<<p)-1))<<(8-p);
|
||||
d |= this[--i]>>(p+=this.DB-8);
|
||||
}
|
||||
else {
|
||||
d = (this[i]>>(p-=8))&0xff;
|
||||
if(p <= 0) { p += this.DB; --i; }
|
||||
}
|
||||
if((d&0x80) != 0) d |= -256;
|
||||
if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
|
||||
if(k > 0 || d != this.s) r[k++] = d;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function bnEquals(a) { return(this.compareTo(a)==0); }
|
||||
function bnMin(a) { return(this.compareTo(a)<0)?this:a; }
|
||||
function bnMax(a) { return(this.compareTo(a)>0)?this:a; }
|
||||
|
||||
// (protected) r = this op a (bitwise)
|
||||
function bnpBitwiseTo(a,op,r) {
|
||||
var i, f, m = Math.min(a.t,this.t);
|
||||
for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
|
||||
if(a.t < this.t) {
|
||||
f = a.s&this.DM;
|
||||
for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
|
||||
r.t = this.t;
|
||||
}
|
||||
else {
|
||||
f = this.s&this.DM;
|
||||
for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
|
||||
r.t = a.t;
|
||||
}
|
||||
r.s = op(this.s,a.s);
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (public) this & a
|
||||
function op_and(x,y) { return x&y; }
|
||||
function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
|
||||
|
||||
// (public) this | a
|
||||
function op_or(x,y) { return x|y; }
|
||||
function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
|
||||
|
||||
// (public) this ^ a
|
||||
function op_xor(x,y) { return x^y; }
|
||||
function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
|
||||
|
||||
// (public) this & ~a
|
||||
function op_andnot(x,y) { return x&~y; }
|
||||
function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
|
||||
|
||||
// (public) ~this
|
||||
function bnNot() {
|
||||
var r = nbi();
|
||||
for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i];
|
||||
r.t = this.t;
|
||||
r.s = ~this.s;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this << n
|
||||
function bnShiftLeft(n) {
|
||||
var r = nbi();
|
||||
if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this >> n
|
||||
function bnShiftRight(n) {
|
||||
var r = nbi();
|
||||
if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// return index of lowest 1-bit in x, x < 2^31
|
||||
function lbit(x) {
|
||||
if(x == 0) return -1;
|
||||
var r = 0;
|
||||
if((x&0xffff) == 0) { x >>= 16; r += 16; }
|
||||
if((x&0xff) == 0) { x >>= 8; r += 8; }
|
||||
if((x&0xf) == 0) { x >>= 4; r += 4; }
|
||||
if((x&3) == 0) { x >>= 2; r += 2; }
|
||||
if((x&1) == 0) ++r;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) returns index of lowest 1-bit (or -1 if none)
|
||||
function bnGetLowestSetBit() {
|
||||
for(var i = 0; i < this.t; ++i)
|
||||
if(this[i] != 0) return i*this.DB+lbit(this[i]);
|
||||
if(this.s < 0) return this.t*this.DB;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return number of 1 bits in x
|
||||
function cbit(x) {
|
||||
var r = 0;
|
||||
while(x != 0) { x &= x-1; ++r; }
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) return number of set bits
|
||||
function bnBitCount() {
|
||||
var r = 0, x = this.s&this.DM;
|
||||
for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) true iff nth bit is set
|
||||
function bnTestBit(n) {
|
||||
var j = Math.floor(n/this.DB);
|
||||
if(j >= this.t) return(this.s!=0);
|
||||
return((this[j]&(1<<(n%this.DB)))!=0);
|
||||
}
|
||||
|
||||
// (protected) this op (1<<n)
|
||||
function bnpChangeBit(n,op) {
|
||||
var r = BigInteger.ONE.shiftLeft(n);
|
||||
this.bitwiseTo(r,op,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this | (1<<n)
|
||||
function bnSetBit(n) { return this.changeBit(n,op_or); }
|
||||
|
||||
// (public) this & ~(1<<n)
|
||||
function bnClearBit(n) { return this.changeBit(n,op_andnot); }
|
||||
|
||||
// (public) this ^ (1<<n)
|
||||
function bnFlipBit(n) { return this.changeBit(n,op_xor); }
|
||||
|
||||
// (protected) r = this + a
|
||||
function bnpAddTo(a,r) {
|
||||
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||
while(i < m) {
|
||||
c += this[i]+a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
if(a.t < this.t) {
|
||||
c += a.s;
|
||||
while(i < this.t) {
|
||||
c += this[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += this.s;
|
||||
}
|
||||
else {
|
||||
c += this.s;
|
||||
while(i < a.t) {
|
||||
c += a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += a.s;
|
||||
}
|
||||
r.s = (c<0)?-1:0;
|
||||
if(c > 0) r[i++] = c;
|
||||
else if(c < -1) r[i++] = this.DV+c;
|
||||
r.t = i;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (public) this + a
|
||||
function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
|
||||
|
||||
// (public) this - a
|
||||
function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
|
||||
|
||||
// (public) this * a
|
||||
function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
|
||||
|
||||
// (public) this^2
|
||||
function bnSquare() { var r = nbi(); this.squareTo(r); return r; }
|
||||
|
||||
// (public) this / a
|
||||
function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
|
||||
|
||||
// (public) this % a
|
||||
function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
|
||||
|
||||
// (public) [this/a,this%a]
|
||||
function bnDivideAndRemainder(a) {
|
||||
var q = nbi(), r = nbi();
|
||||
this.divRemTo(a,q,r);
|
||||
return new Array(q,r);
|
||||
}
|
||||
|
||||
// (protected) this *= n, this >= 0, 1 < n < DV
|
||||
function bnpDMultiply(n) {
|
||||
this[this.t] = this.am(0,n-1,this,0,0,this.t);
|
||||
++this.t;
|
||||
this.clamp();
|
||||
}
|
||||
|
||||
// (protected) this += n << w words, this >= 0
|
||||
function bnpDAddOffset(n,w) {
|
||||
if(n == 0) return;
|
||||
while(this.t <= w) this[this.t++] = 0;
|
||||
this[w] += n;
|
||||
while(this[w] >= this.DV) {
|
||||
this[w] -= this.DV;
|
||||
if(++w >= this.t) this[this.t++] = 0;
|
||||
++this[w];
|
||||
}
|
||||
}
|
||||
|
||||
// A "null" reducer
|
||||
function NullExp() {}
|
||||
function nNop(x) { return x; }
|
||||
function nMulTo(x,y,r) { x.multiplyTo(y,r); }
|
||||
function nSqrTo(x,r) { x.squareTo(r); }
|
||||
|
||||
NullExp.prototype.convert = nNop;
|
||||
NullExp.prototype.revert = nNop;
|
||||
NullExp.prototype.mulTo = nMulTo;
|
||||
NullExp.prototype.sqrTo = nSqrTo;
|
||||
|
||||
// (public) this^e
|
||||
function bnPow(e) { return this.exp(e,new NullExp()); }
|
||||
|
||||
// (protected) r = lower n words of "this * a", a.t <= n
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyLowerTo(a,n,r) {
|
||||
var i = Math.min(this.t+a.t,n);
|
||||
r.s = 0; // assumes a,this >= 0
|
||||
r.t = i;
|
||||
while(i > 0) r[--i] = 0;
|
||||
var j;
|
||||
for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
|
||||
for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = "this * a" without lower n words, n > 0
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyUpperTo(a,n,r) {
|
||||
--n;
|
||||
var i = r.t = this.t+a.t-n;
|
||||
r.s = 0; // assumes a,this >= 0
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = Math.max(n-this.t,0); i < a.t; ++i)
|
||||
r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
|
||||
r.clamp();
|
||||
r.drShiftTo(1,r);
|
||||
}
|
||||
|
||||
// Barrett modular reduction
|
||||
function Barrett(m) {
|
||||
// setup Barrett
|
||||
this.r2 = nbi();
|
||||
this.q3 = nbi();
|
||||
BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
|
||||
this.mu = this.r2.divide(m);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
function barrettConvert(x) {
|
||||
if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
|
||||
else if(x.compareTo(this.m) < 0) return x;
|
||||
else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
|
||||
}
|
||||
|
||||
function barrettRevert(x) { return x; }
|
||||
|
||||
// x = x mod m (HAC 14.42)
|
||||
function barrettReduce(x) {
|
||||
x.drShiftTo(this.m.t-1,this.r2);
|
||||
if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
|
||||
this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
|
||||
this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
|
||||
while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
|
||||
x.subTo(this.r2,x);
|
||||
while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||
}
|
||||
|
||||
// r = x^2 mod m; x != r
|
||||
function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
// r = x*y mod m; x,y != r
|
||||
function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
|
||||
Barrett.prototype.convert = barrettConvert;
|
||||
Barrett.prototype.revert = barrettRevert;
|
||||
Barrett.prototype.reduce = barrettReduce;
|
||||
Barrett.prototype.mulTo = barrettMulTo;
|
||||
Barrett.prototype.sqrTo = barrettSqrTo;
|
||||
|
||||
// (public) this^e % m (HAC 14.85)
|
||||
function bnModPow(e,m) {
|
||||
var i = e.bitLength(), k, r = nbv(1), z;
|
||||
if(i <= 0) return r;
|
||||
else if(i < 18) k = 1;
|
||||
else if(i < 48) k = 3;
|
||||
else if(i < 144) k = 4;
|
||||
else if(i < 768) k = 5;
|
||||
else k = 6;
|
||||
if(i < 8)
|
||||
z = new Classic(m);
|
||||
else if(m.isEven())
|
||||
z = new Barrett(m);
|
||||
else
|
||||
z = new Montgomery(m);
|
||||
|
||||
// precomputation
|
||||
var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
|
||||
g[1] = z.convert(this);
|
||||
if(k > 1) {
|
||||
var g2 = nbi();
|
||||
z.sqrTo(g[1],g2);
|
||||
while(n <= km) {
|
||||
g[n] = nbi();
|
||||
z.mulTo(g2,g[n-2],g[n]);
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
|
||||
var j = e.t-1, w, is1 = true, r2 = nbi(), t;
|
||||
i = nbits(e[j])-1;
|
||||
while(j >= 0) {
|
||||
if(i >= k1) w = (e[j]>>(i-k1))&km;
|
||||
else {
|
||||
w = (e[j]&((1<<(i+1))-1))<<(k1-i);
|
||||
if(j > 0) w |= e[j-1]>>(this.DB+i-k1);
|
||||
}
|
||||
|
||||
n = k;
|
||||
while((w&1) == 0) { w >>= 1; --n; }
|
||||
if((i -= n) < 0) { i += this.DB; --j; }
|
||||
if(is1) { // ret == 1, don't bother squaring or multiplying it
|
||||
g[w].copyTo(r);
|
||||
is1 = false;
|
||||
}
|
||||
else {
|
||||
while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
|
||||
if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
|
||||
z.mulTo(r2,g[w],r);
|
||||
}
|
||||
|
||||
while(j >= 0 && (e[j]&(1<<i)) == 0) {
|
||||
z.sqrTo(r,r2); t = r; r = r2; r2 = t;
|
||||
if(--i < 0) { i = this.DB-1; --j; }
|
||||
}
|
||||
}
|
||||
return z.revert(r);
|
||||
}
|
||||
|
||||
// (public) gcd(this,a) (HAC 14.54)
|
||||
function bnGCD(a) {
|
||||
var x = (this.s<0)?this.negate():this.clone();
|
||||
var y = (a.s<0)?a.negate():a.clone();
|
||||
if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
|
||||
var i = x.getLowestSetBit(), g = y.getLowestSetBit();
|
||||
if(g < 0) return x;
|
||||
if(i < g) g = i;
|
||||
if(g > 0) {
|
||||
x.rShiftTo(g,x);
|
||||
y.rShiftTo(g,y);
|
||||
}
|
||||
while(x.signum() > 0) {
|
||||
if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
|
||||
if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
|
||||
if(x.compareTo(y) >= 0) {
|
||||
x.subTo(y,x);
|
||||
x.rShiftTo(1,x);
|
||||
}
|
||||
else {
|
||||
y.subTo(x,y);
|
||||
y.rShiftTo(1,y);
|
||||
}
|
||||
}
|
||||
if(g > 0) y.lShiftTo(g,y);
|
||||
return y;
|
||||
}
|
||||
|
||||
// (protected) this % n, n < 2^26
|
||||
function bnpModInt(n) {
|
||||
if(n <= 0) return 0;
|
||||
var d = this.DV%n, r = (this.s<0)?n-1:0;
|
||||
if(this.t > 0)
|
||||
if(d == 0) r = this[0]%n;
|
||||
else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) 1/this % m (HAC 14.61)
|
||||
function bnModInverse(m) {
|
||||
var ac = m.isEven();
|
||||
if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
|
||||
var u = m.clone(), v = this.clone();
|
||||
var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
|
||||
while(u.signum() != 0) {
|
||||
while(u.isEven()) {
|
||||
u.rShiftTo(1,u);
|
||||
if(ac) {
|
||||
if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
|
||||
a.rShiftTo(1,a);
|
||||
}
|
||||
else if(!b.isEven()) b.subTo(m,b);
|
||||
b.rShiftTo(1,b);
|
||||
}
|
||||
while(v.isEven()) {
|
||||
v.rShiftTo(1,v);
|
||||
if(ac) {
|
||||
if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
|
||||
c.rShiftTo(1,c);
|
||||
}
|
||||
else if(!d.isEven()) d.subTo(m,d);
|
||||
d.rShiftTo(1,d);
|
||||
}
|
||||
if(u.compareTo(v) >= 0) {
|
||||
u.subTo(v,u);
|
||||
if(ac) a.subTo(c,a);
|
||||
b.subTo(d,b);
|
||||
}
|
||||
else {
|
||||
v.subTo(u,v);
|
||||
if(ac) c.subTo(a,c);
|
||||
d.subTo(b,d);
|
||||
}
|
||||
}
|
||||
if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
|
||||
if(d.compareTo(m) >= 0) return d.subtract(m);
|
||||
if(d.signum() < 0) d.addTo(m,d); else return d;
|
||||
if(d.signum() < 0) return d.add(m); else return d;
|
||||
}
|
||||
|
||||
var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];
|
||||
var lplim = (1<<26)/lowprimes[lowprimes.length-1];
|
||||
|
||||
// (public) test primality with certainty >= 1-.5^t
|
||||
function bnIsProbablePrime(t) {
|
||||
var i, x = this.abs();
|
||||
if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
|
||||
for(i = 0; i < lowprimes.length; ++i)
|
||||
if(x[0] == lowprimes[i]) return true;
|
||||
return false;
|
||||
}
|
||||
if(x.isEven()) return false;
|
||||
i = 1;
|
||||
while(i < lowprimes.length) {
|
||||
var m = lowprimes[i], j = i+1;
|
||||
while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
|
||||
m = x.modInt(m);
|
||||
while(i < j) if(m%lowprimes[i++] == 0) return false;
|
||||
}
|
||||
return x.millerRabin(t);
|
||||
}
|
||||
|
||||
// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
||||
function bnpMillerRabin(t) {
|
||||
var n1 = this.subtract(BigInteger.ONE);
|
||||
var k = n1.getLowestSetBit();
|
||||
if(k <= 0) return false;
|
||||
var r = n1.shiftRight(k);
|
||||
t = (t+1)>>1;
|
||||
if(t > lowprimes.length) t = lowprimes.length;
|
||||
var a = nbi();
|
||||
for(var i = 0; i < t; ++i) {
|
||||
//Pick bases at random, instead of starting at 2
|
||||
a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);
|
||||
var y = a.modPow(r,this);
|
||||
if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
|
||||
var j = 1;
|
||||
while(j++ < k && y.compareTo(n1) != 0) {
|
||||
y = y.modPowInt(2,this);
|
||||
if(y.compareTo(BigInteger.ONE) == 0) return false;
|
||||
}
|
||||
if(y.compareTo(n1) != 0) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// protected
|
||||
BigInteger.prototype.chunkSize = bnpChunkSize;
|
||||
BigInteger.prototype.toRadix = bnpToRadix;
|
||||
BigInteger.prototype.fromRadix = bnpFromRadix;
|
||||
BigInteger.prototype.fromNumber = bnpFromNumber;
|
||||
BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
|
||||
BigInteger.prototype.changeBit = bnpChangeBit;
|
||||
BigInteger.prototype.addTo = bnpAddTo;
|
||||
BigInteger.prototype.dMultiply = bnpDMultiply;
|
||||
BigInteger.prototype.dAddOffset = bnpDAddOffset;
|
||||
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
|
||||
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
|
||||
BigInteger.prototype.modInt = bnpModInt;
|
||||
BigInteger.prototype.millerRabin = bnpMillerRabin;
|
||||
|
||||
// public
|
||||
BigInteger.prototype.clone = bnClone;
|
||||
BigInteger.prototype.intValue = bnIntValue;
|
||||
BigInteger.prototype.byteValue = bnByteValue;
|
||||
BigInteger.prototype.shortValue = bnShortValue;
|
||||
BigInteger.prototype.signum = bnSigNum;
|
||||
BigInteger.prototype.toByteArray = bnToByteArray;
|
||||
BigInteger.prototype.equals = bnEquals;
|
||||
BigInteger.prototype.min = bnMin;
|
||||
BigInteger.prototype.max = bnMax;
|
||||
BigInteger.prototype.and = bnAnd;
|
||||
BigInteger.prototype.or = bnOr;
|
||||
BigInteger.prototype.xor = bnXor;
|
||||
BigInteger.prototype.andNot = bnAndNot;
|
||||
BigInteger.prototype.not = bnNot;
|
||||
BigInteger.prototype.shiftLeft = bnShiftLeft;
|
||||
BigInteger.prototype.shiftRight = bnShiftRight;
|
||||
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
|
||||
BigInteger.prototype.bitCount = bnBitCount;
|
||||
BigInteger.prototype.testBit = bnTestBit;
|
||||
BigInteger.prototype.setBit = bnSetBit;
|
||||
BigInteger.prototype.clearBit = bnClearBit;
|
||||
BigInteger.prototype.flipBit = bnFlipBit;
|
||||
BigInteger.prototype.add = bnAdd;
|
||||
BigInteger.prototype.subtract = bnSubtract;
|
||||
BigInteger.prototype.multiply = bnMultiply;
|
||||
BigInteger.prototype.divide = bnDivide;
|
||||
BigInteger.prototype.remainder = bnRemainder;
|
||||
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
|
||||
BigInteger.prototype.modPow = bnModPow;
|
||||
BigInteger.prototype.modInverse = bnModInverse;
|
||||
BigInteger.prototype.pow = bnPow;
|
||||
BigInteger.prototype.gcd = bnGCD;
|
||||
BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
|
||||
|
||||
// JSBN-specific extension
|
||||
BigInteger.prototype.square = bnSquare;
|
||||
|
||||
// BigInteger interfaces not implemented in jsbn:
|
||||
|
||||
// BigInteger(int signum, byte[] magnitude)
|
||||
// double doubleValue()
|
||||
// float floatValue()
|
||||
// int hashCode()
|
||||
// long longValue()
|
||||
// static BigInteger valueOf(long val)
|
45
javascript/jsbn/prng4.js
Normal file
45
javascript/jsbn/prng4.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
// prng4.js - uses Arcfour as a PRNG
|
||||
|
||||
function Arcfour() {
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
this.S = new Array();
|
||||
}
|
||||
|
||||
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
||||
function ARC4init(key) {
|
||||
var i, j, t;
|
||||
for(i = 0; i < 256; ++i)
|
||||
this.S[i] = i;
|
||||
j = 0;
|
||||
for(i = 0; i < 256; ++i) {
|
||||
j = (j + this.S[i] + key[i % key.length]) & 255;
|
||||
t = this.S[i];
|
||||
this.S[i] = this.S[j];
|
||||
this.S[j] = t;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
function ARC4next() {
|
||||
var t;
|
||||
this.i = (this.i + 1) & 255;
|
||||
this.j = (this.j + this.S[this.i]) & 255;
|
||||
t = this.S[this.i];
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = t;
|
||||
return this.S[(t + this.S[this.i]) & 255];
|
||||
}
|
||||
|
||||
Arcfour.prototype.init = ARC4init;
|
||||
Arcfour.prototype.next = ARC4next;
|
||||
|
||||
// Plug in your RNG constructor here
|
||||
function prng_newstate() {
|
||||
return new Arcfour();
|
||||
}
|
||||
|
||||
// Pool size must be a multiple of 4 and greater than 32.
|
||||
// An array of bytes the size of the pool will be passed to init()
|
||||
var rng_psize = 256;
|
75
javascript/jsbn/rng.js
Normal file
75
javascript/jsbn/rng.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
||||
|
||||
// For best results, put code like
|
||||
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
||||
// in your main HTML document.
|
||||
|
||||
var rng_state;
|
||||
var rng_pool;
|
||||
var rng_pptr;
|
||||
|
||||
// Mix in a 32-bit integer into the pool
|
||||
function rng_seed_int(x) {
|
||||
rng_pool[rng_pptr++] ^= x & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
|
||||
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
|
||||
}
|
||||
|
||||
// Mix in the current time (w/milliseconds) into the pool
|
||||
function rng_seed_time() {
|
||||
rng_seed_int(new Date().getTime());
|
||||
}
|
||||
|
||||
// Initialize the pool with junk if needed.
|
||||
if(rng_pool == null) {
|
||||
rng_pool = new Array();
|
||||
rng_pptr = 0;
|
||||
var t;
|
||||
if(window.crypto && window.crypto.getRandomValues) {
|
||||
// Use webcrypto if available
|
||||
var ua = new Uint8Array(32);
|
||||
window.crypto.getRandomValues(ua);
|
||||
for(t = 0; t < 32; ++t)
|
||||
rng_pool[rng_pptr++] = ua[t];
|
||||
}
|
||||
if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
|
||||
// Extract entropy (256 bits) from NS4 RNG if available
|
||||
var z = window.crypto.random(32);
|
||||
for(t = 0; t < z.length; ++t)
|
||||
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
||||
}
|
||||
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
|
||||
t = Math.floor(65536 * Math.random());
|
||||
rng_pool[rng_pptr++] = t >>> 8;
|
||||
rng_pool[rng_pptr++] = t & 255;
|
||||
}
|
||||
rng_pptr = 0;
|
||||
rng_seed_time();
|
||||
//rng_seed_int(window.screenX);
|
||||
//rng_seed_int(window.screenY);
|
||||
}
|
||||
|
||||
function rng_get_byte() {
|
||||
if(rng_state == null) {
|
||||
rng_seed_time();
|
||||
rng_state = prng_newstate();
|
||||
rng_state.init(rng_pool);
|
||||
for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
||||
rng_pool[rng_pptr] = 0;
|
||||
rng_pptr = 0;
|
||||
//rng_pool = null;
|
||||
}
|
||||
// TODO: allow reseeding after first request
|
||||
return rng_state.next();
|
||||
}
|
||||
|
||||
function rng_get_bytes(ba) {
|
||||
var i;
|
||||
for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
|
||||
}
|
||||
|
||||
function SecureRandom() {}
|
||||
|
||||
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
118
javascript/jsbn/rsa.js
Normal file
118
javascript/jsbn/rsa.js
Normal file
|
@ -0,0 +1,118 @@
|
|||
// Depends on jsbn.js and rng.js
|
||||
|
||||
// Version 1.1: support utf-8 encoding in pkcs1pad2
|
||||
|
||||
// convert a (hex) string to a bignum object
|
||||
function parseBigInt(str,r) {
|
||||
return new BigInteger(str,r);
|
||||
}
|
||||
|
||||
function linebrk(s,n) {
|
||||
var ret = "";
|
||||
var i = 0;
|
||||
while(i + n < s.length) {
|
||||
ret += s.substring(i,i+n) + "\n";
|
||||
i += n;
|
||||
}
|
||||
return ret + s.substring(i,s.length);
|
||||
}
|
||||
|
||||
function byte2Hex(b) {
|
||||
if(b < 0x10)
|
||||
return "0" + b.toString(16);
|
||||
else
|
||||
return b.toString(16);
|
||||
}
|
||||
|
||||
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
|
||||
function pkcs1pad2(s,n) {
|
||||
//var ba = b64toBA(hex2b64(s));
|
||||
//n -= ba.length;
|
||||
if(n < s.length + 11) { // TODO: fix for utf-8
|
||||
alert("Message too long for RSA");
|
||||
return null;
|
||||
}
|
||||
var ba = new Array();
|
||||
var i = (s.length / 2) - 1;
|
||||
while(i >= 0 && n > 0) {
|
||||
ba[--n] = parseInt(s.substring(2*i,2*i+2),16);
|
||||
i--;
|
||||
/*
|
||||
var c = s.charCodeAt(i--);
|
||||
if(c < 128) { // encode using utf-8
|
||||
ba[--n] = c;
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = (c >> 6) | 192;
|
||||
}
|
||||
else {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = ((c >> 6) & 63) | 128;
|
||||
ba[--n] = (c >> 12) | 224;
|
||||
}
|
||||
*/
|
||||
}
|
||||
ba[--n] = 0;
|
||||
var rng = new SecureRandom();
|
||||
var x = new Array();
|
||||
while(n > 2) { // random non-zero pad
|
||||
x[0] = 0;
|
||||
while(x[0] == 0) rng.nextBytes(x);
|
||||
ba[--n] = x[0];
|
||||
}
|
||||
ba[--n] = 2;
|
||||
ba[--n] = 0;
|
||||
return new BigInteger(ba);
|
||||
}
|
||||
|
||||
// "empty" RSA key constructor
|
||||
function RSAKey() {
|
||||
this.n = null;
|
||||
this.e = 0;
|
||||
this.d = null;
|
||||
this.p = null;
|
||||
this.q = null;
|
||||
this.dmp1 = null;
|
||||
this.dmq1 = null;
|
||||
this.coeff = null;
|
||||
}
|
||||
|
||||
// Set the public key fields N and e from hex strings
|
||||
function RSASetPublic(N,E) {
|
||||
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||
this.n = parseBigInt(N,16);
|
||||
this.e = parseInt(E,16);
|
||||
}
|
||||
else
|
||||
alert("Invalid RSA public key");
|
||||
}
|
||||
|
||||
// Perform raw public operation on "x": return x^e (mod n)
|
||||
function RSADoPublic(x) {
|
||||
return x.modPowInt(this.e, this.n);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
|
||||
function RSAEncrypt(text) {
|
||||
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
|
||||
if(m == null) return null;
|
||||
var c = this.doPublic(m);
|
||||
if(c == null) return null;
|
||||
var h = c.toString(16);
|
||||
if((h.length & 1) == 0) return h; else return "0" + h;
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
|
||||
//function RSAEncryptB64(text) {
|
||||
// var h = this.encrypt(text);
|
||||
// if(h) return hex2b64(h); else return null;
|
||||
//}
|
||||
|
||||
// protected
|
||||
RSAKey.prototype.doPublic = RSADoPublic;
|
||||
|
||||
// public
|
||||
RSAKey.prototype.setPublic = RSASetPublic;
|
||||
RSAKey.prototype.encrypt = RSAEncrypt;
|
||||
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
|
135
javascript/jsbn/rsa2.js
Normal file
135
javascript/jsbn/rsa2.js
Normal file
|
@ -0,0 +1,135 @@
|
|||
// Depends on rsa.js and jsbn2.js
|
||||
|
||||
// Version 1.1: support utf-8 decoding in pkcs1unpad2
|
||||
|
||||
// Undo PKCS#1 (type 2, random) padding and, if valid, return the plaintext
|
||||
function pkcs1unpad2(d,n) {
|
||||
var b = d.toByteArray();
|
||||
var i = 0;
|
||||
while(i < b.length && b[i] == 0) ++i;
|
||||
if(b.length-i != n-1 || b[i] != 2)
|
||||
return null;
|
||||
++i;
|
||||
while(b[i] != 0)
|
||||
if(++i >= b.length) return null;
|
||||
var ret = "";
|
||||
while(++i < b.length) {
|
||||
ret += byte2Hex(b[i]);
|
||||
/*
|
||||
var c = b[i] & 255;
|
||||
if(c < 128) { // utf-8 decode
|
||||
ret += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 191) && (c < 224)) {
|
||||
ret += String.fromCharCode(((c & 31) << 6) | (b[i+1] & 63));
|
||||
++i;
|
||||
}
|
||||
else {
|
||||
ret += String.fromCharCode(((c & 15) << 12) | ((b[i+1] & 63) << 6) | (b[i+2] & 63));
|
||||
i += 2;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Set the private key fields N, e, and d from hex strings
|
||||
function RSASetPrivate(N,E,D) {
|
||||
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||
this.n = parseBigInt(N,16);
|
||||
this.e = parseInt(E,16);
|
||||
this.d = parseBigInt(D,16);
|
||||
}
|
||||
else
|
||||
alert("Invalid RSA private key");
|
||||
}
|
||||
|
||||
// Set the private key fields N, e, d and CRT params from hex strings
|
||||
function RSASetPrivateEx(N,E,D,P,Q,DP,DQ,C) {
|
||||
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||
this.n = parseBigInt(N,16);
|
||||
this.e = parseInt(E,16);
|
||||
this.d = parseBigInt(D,16);
|
||||
this.p = parseBigInt(P,16);
|
||||
this.q = parseBigInt(Q,16);
|
||||
this.dmp1 = parseBigInt(DP,16);
|
||||
this.dmq1 = parseBigInt(DQ,16);
|
||||
this.coeff = parseBigInt(C,16);
|
||||
}
|
||||
else
|
||||
alert("Invalid RSA private key");
|
||||
}
|
||||
|
||||
// Generate a new random private key B bits long, using public expt E
|
||||
function RSAGenerate(B,E) {
|
||||
var rng = new SecureRandom();
|
||||
var qs = B>>1;
|
||||
this.e = parseInt(E,16);
|
||||
var ee = new BigInteger(E,16);
|
||||
for(;;) {
|
||||
for(;;) {
|
||||
this.p = new BigInteger(B-qs,1,rng);
|
||||
if(this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.p.isProbablePrime(10)) break;
|
||||
}
|
||||
for(;;) {
|
||||
this.q = new BigInteger(qs,1,rng);
|
||||
if(this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.q.isProbablePrime(10)) break;
|
||||
}
|
||||
if(this.p.compareTo(this.q) <= 0) {
|
||||
var t = this.p;
|
||||
this.p = this.q;
|
||||
this.q = t;
|
||||
}
|
||||
var p1 = this.p.subtract(BigInteger.ONE);
|
||||
var q1 = this.q.subtract(BigInteger.ONE);
|
||||
var phi = p1.multiply(q1);
|
||||
if(phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
|
||||
this.n = this.p.multiply(this.q);
|
||||
this.d = ee.modInverse(phi);
|
||||
this.dmp1 = this.d.mod(p1);
|
||||
this.dmq1 = this.d.mod(q1);
|
||||
this.coeff = this.q.modInverse(this.p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform raw private operation on "x": return x^d (mod n)
|
||||
function RSADoPrivate(x) {
|
||||
if(this.p == null || this.q == null)
|
||||
return x.modPow(this.d, this.n);
|
||||
|
||||
// TODO: re-calculate any missing CRT params
|
||||
var xp = x.mod(this.p).modPow(this.dmp1, this.p);
|
||||
var xq = x.mod(this.q).modPow(this.dmq1, this.q);
|
||||
|
||||
while(xp.compareTo(xq) < 0)
|
||||
xp = xp.add(this.p);
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA decryption of "ctext".
|
||||
// "ctext" is an even-length hex string and the output is a plain string.
|
||||
function RSADecrypt(ctext) {
|
||||
var c = parseBigInt(ctext, 16);
|
||||
var m = this.doPrivate(c);
|
||||
if(m == null) return null;
|
||||
return pkcs1unpad2(m, (this.n.bitLength()+7)>>3);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA decryption of "ctext".
|
||||
// "ctext" is a Base64-encoded string and the output is a plain string.
|
||||
//function RSAB64Decrypt(ctext) {
|
||||
// var h = b64tohex(ctext);
|
||||
// if(h) return this.decrypt(h); else return null;
|
||||
//}
|
||||
|
||||
// protected
|
||||
RSAKey.prototype.doPrivate = RSADoPrivate;
|
||||
|
||||
// public
|
||||
RSAKey.prototype.setPrivate = RSASetPrivate;
|
||||
RSAKey.prototype.setPrivateEx = RSASetPrivateEx;
|
||||
RSAKey.prototype.generate = RSAGenerate;
|
||||
RSAKey.prototype.decrypt = RSADecrypt;
|
||||
//RSAKey.prototype.b64_decrypt = RSAB64Decrypt;
|
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,8 @@
|
|||
ayuncraft is a modded version of eaglercraft. check it out for yourself to see what's different!
|
||||
|
||||
|
||||
-=-The following is the original README file-=-
|
||||
|
||||
eaglercraft is an AOT compiled port of mojang's minecraft 1.5.2 designed to run in an html5/javascript environment, using TeaVM and my opengl 1.3 emulator to simulate a desktop java enviroment fully compatible with minecraft java edition
|
||||
|
||||
§1this §1was §1created §1by §1calder §1young §1(LAX1DUDE), §1submit §1complaints §1and §1bug §1reports §1to §1cgiacun@gmail.com §1or §1hmu §1on §1discord §1at §1LAX1DUDE#6306 §1or §1on §1instagram §1@calderyounggg§r
|
||||
|
|
242
src/lwjgl/java/me/ayunami2000/ayuncraft/CryptManager.java
Normal file
242
src/lwjgl/java/me/ayunami2000/ayuncraft/CryptManager.java
Normal file
|
@ -0,0 +1,242 @@
|
|||
package me.ayunami2000.ayuncraft;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.CipherKeyGenerator;
|
||||
import org.bouncycastle.crypto.KeyGenerationParameters;
|
||||
import org.bouncycastle.crypto.engines.AESFastEngine;
|
||||
import org.bouncycastle.crypto.io.CipherInputStream;
|
||||
import org.bouncycastle.crypto.io.CipherOutputStream;
|
||||
import org.bouncycastle.crypto.modes.CFBBlockCipher;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
public class CryptManager
|
||||
{
|
||||
/** ISO_8859_1 */
|
||||
public static final Charset charSet = Charset.forName("ISO_8859_1");
|
||||
|
||||
/**
|
||||
* Generate a new shared secret AES key from a secure random source
|
||||
*/
|
||||
public static SecretKey createNewSharedKey()
|
||||
{
|
||||
CipherKeyGenerator var0 = new CipherKeyGenerator();
|
||||
var0.init(new KeyGenerationParameters(new SecureRandom(), 128));
|
||||
return (SecretKey) new SecretKeySpec(var0.generateKey(), "AES");
|
||||
}
|
||||
|
||||
public static KeyPair createNewKeyPair()
|
||||
{
|
||||
try
|
||||
{
|
||||
KeyPairGenerator var0 = KeyPairGenerator.getInstance("RSA");
|
||||
var0.initialize(1024);
|
||||
return var0.generateKeyPair();
|
||||
}
|
||||
catch (NoSuchAlgorithmException var1)
|
||||
{
|
||||
var1.printStackTrace();
|
||||
System.err.println("Key pair generation failed!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a serverId hash for use by sendSessionRequest()
|
||||
*/
|
||||
public static byte[] getServerIdHash(String par0Str, PublicKey par1PublicKey, SecretKey par2SecretKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return digestOperation("SHA-1", new byte[][] {par0Str.getBytes("ISO_8859_1"), par2SecretKey.getEncoded(), par1PublicKey.getEncoded()});
|
||||
}
|
||||
catch (UnsupportedEncodingException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a message digest on arbitrary byte[] data
|
||||
*/
|
||||
private static byte[] digestOperation(String par0Str, byte[] ... par1ArrayOfByte)
|
||||
{
|
||||
try
|
||||
{
|
||||
MessageDigest var2 = MessageDigest.getInstance(par0Str);
|
||||
byte[][] var3 = par1ArrayOfByte;
|
||||
int var4 = par1ArrayOfByte.length;
|
||||
|
||||
for (int var5 = 0; var5 < var4; ++var5)
|
||||
{
|
||||
byte[] var6 = var3[var5];
|
||||
var2.update(var6);
|
||||
}
|
||||
|
||||
return var2.digest();
|
||||
}
|
||||
catch (NoSuchAlgorithmException var7)
|
||||
{
|
||||
var7.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PublicKey from encoded X.509 data
|
||||
*/
|
||||
public static PublicKey decodePublicKey(byte[] par0ArrayOfByte)
|
||||
{
|
||||
try
|
||||
{
|
||||
X509EncodedKeySpec var1 = new X509EncodedKeySpec(par0ArrayOfByte);
|
||||
KeyFactory var2 = KeyFactory.getInstance("RSA");
|
||||
return (PublicKey) var2.generatePublic(var1);
|
||||
}
|
||||
catch (NoSuchAlgorithmException var3)
|
||||
{
|
||||
var3.printStackTrace();
|
||||
}
|
||||
catch (InvalidKeySpecException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
}
|
||||
|
||||
System.err.println("Public key reconstitute failed!");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt shared secret AES key using RSA private key
|
||||
*/
|
||||
public static SecretKey decryptSharedKey(PrivateKey par0PrivateKey, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return (SecretKey) new SecretKeySpec(decryptData((Key) par0PrivateKey, par1ArrayOfByte), "AES");
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt byte[] data with RSA public key
|
||||
*/
|
||||
public static byte[] encryptData(Key par0Key, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return cipherOperation(1, par0Key, par1ArrayOfByte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt byte[] data with RSA private key
|
||||
*/
|
||||
public static byte[] decryptData(Key par0Key, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return cipherOperation(2, par0Key, par1ArrayOfByte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt or decrypt byte[] data using the specified key
|
||||
*/
|
||||
private static byte[] cipherOperation(int par0, Key par1Key, byte[] par2ArrayOfByte)
|
||||
{
|
||||
try
|
||||
{
|
||||
return createTheCipherInstance(par0, par1Key.getAlgorithm(), par1Key).doFinal(par2ArrayOfByte);
|
||||
}
|
||||
catch (IllegalBlockSizeException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
}
|
||||
catch (BadPaddingException var5)
|
||||
{
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
System.err.println("Cipher data failed!");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Cipher Instance.
|
||||
*/
|
||||
private static Cipher createTheCipherInstance(int par0, String par1Str, Key par2Key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Cipher var3 = Cipher.getInstance(par1Str);
|
||||
var3.init(par0, (java.security.Key) par2Key);
|
||||
return var3;
|
||||
}
|
||||
catch (InvalidKeyException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
}
|
||||
catch (NoSuchAlgorithmException var5)
|
||||
{
|
||||
var5.printStackTrace();
|
||||
}
|
||||
catch (NoSuchPaddingException var6)
|
||||
{
|
||||
var6.printStackTrace();
|
||||
}
|
||||
|
||||
System.err.println("Cipher creation failed!");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new BufferedBlockCipher instance
|
||||
*/
|
||||
public static BufferedBlockCipher createBufferedBlockCipher(boolean par0, Key par1Key)
|
||||
{
|
||||
BufferedBlockCipher var2 = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
|
||||
var2.init(par0, new ParametersWithIV(new KeyParameter(par1Key.getEncoded()), par1Key.getEncoded(), 0, 16));
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static OutputStream encryptOuputStream(SecretKey par0SecretKey, OutputStream par1OutputStream)
|
||||
{
|
||||
return new CipherOutputStream(par1OutputStream, createBufferedBlockCipher(true, (Key) par0SecretKey));
|
||||
}
|
||||
|
||||
public static InputStream decryptInputStream(SecretKey par0SecretKey, InputStream par1InputStream)
|
||||
{
|
||||
return new CipherInputStream(par1InputStream, createBufferedBlockCipher(false, (Key) par0SecretKey));
|
||||
}
|
||||
|
||||
public static OutputStream encryptOuputStream(BufferedBlockCipher bufferedBlockCipher, OutputStream par1OutputStream)
|
||||
{
|
||||
return new CipherOutputStream(par1OutputStream, bufferedBlockCipher);
|
||||
}
|
||||
|
||||
public static InputStream decryptInputStream(BufferedBlockCipher bufferedBlockCipher, InputStream par1InputStream)
|
||||
{
|
||||
return new CipherInputStream(par1InputStream, bufferedBlockCipher);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,263 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import java.security.Key;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.*;
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class WebsocketNetworkManager implements INetworkManager {
|
||||
private boolean isInputBeingDecrypted;
|
||||
private boolean isOutputEncrypted;
|
||||
private SecretKey sharedKeyForEncryption;
|
||||
|
||||
private final boolean logpackets=false;
|
||||
|
||||
private BufferedBlockCipher inputBufferedBlockCipher=null;
|
||||
private BufferedBlockCipher outputBufferedBlockCipher=null;
|
||||
|
||||
private NetHandler netHandler;
|
||||
|
||||
public WebsocketNetworkManager(String uri, String eagler, NetHandler netHandler) throws IOException {
|
||||
this.netHandler = netHandler;
|
||||
this.sharedKeyForEncryption = null;
|
||||
this.isInputBeingDecrypted = false;
|
||||
this.isOutputEncrypted = false;
|
||||
if(!EaglerAdapter.startConnection(uri)) {
|
||||
throw new IOException("websocket to "+uri+" failed");
|
||||
}
|
||||
EaglerAdapter.setDebugVar("minecraftServer", uri);
|
||||
}
|
||||
|
||||
public void setNetHandler(NetHandler netHandler) {
|
||||
this.netHandler = netHandler;
|
||||
}
|
||||
|
||||
private ByteArrayOutputStream sendBuffer = new ByteArrayOutputStream();
|
||||
|
||||
public void addToSendQueue(Packet var1) {
|
||||
try {
|
||||
sendBuffer.reset();
|
||||
|
||||
DataOutputStream yee;
|
||||
if(this.isOutputEncrypted&&!(var1 instanceof Packet252SharedKey)){
|
||||
yee = this.encryptOuputStream();
|
||||
}else{
|
||||
yee = new DataOutputStream(sendBuffer);
|
||||
}
|
||||
|
||||
if (Minecraft.getMinecraft().gameSettings.useDefaultProtocol && var1 instanceof Packet252SharedKey && !this.isOutputEncrypted)
|
||||
{
|
||||
this.sharedKeyForEncryption = ((Packet252SharedKey)var1).getSharedKey();
|
||||
this.isOutputEncrypted=true;
|
||||
//yee=this.encryptOuputStream(yee);
|
||||
}
|
||||
Packet.writePacket(var1, yee);
|
||||
if(logpackets)System.out.println("SENDING: "+var1);
|
||||
yee.flush();
|
||||
EaglerAdapter.writePacket(sendBuffer.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeThreads() {
|
||||
}
|
||||
|
||||
private static class ByteBufferDirectInputStream extends InputStream {
|
||||
private ByteBuffer buf;
|
||||
private ByteBufferDirectInputStream(ByteBuffer b) {
|
||||
this.buf = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return buf.remaining() > 0 ? ((int)buf.get() & 0xFF) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return buf.remaining();
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer oldChunkBuffer = null;
|
||||
private LinkedList<ByteBuffer> readChunks = new LinkedList();
|
||||
|
||||
private ByteBuffer oldDecryptedChunkBuffer = null;
|
||||
private LinkedList<ByteBuffer> decryptedReadChunks = new LinkedList();
|
||||
|
||||
public void processReadPackets() {
|
||||
readChunks.clear();
|
||||
|
||||
if(oldChunkBuffer != null) {
|
||||
readChunks.add(oldChunkBuffer);
|
||||
}
|
||||
|
||||
byte[] packet;
|
||||
while((packet = EaglerAdapter.readPacket()) != null) {
|
||||
readChunks.add(ByteBuffer.wrap(packet));
|
||||
}
|
||||
if(!readChunks.isEmpty()) {
|
||||
|
||||
int cap = 0;
|
||||
for(ByteBuffer b : readChunks) {
|
||||
cap += b.limit();
|
||||
}
|
||||
|
||||
ByteBuffer stream = ByteBuffer.allocate(cap);
|
||||
for(ByteBuffer b : readChunks) {
|
||||
stream.put(b);
|
||||
}
|
||||
stream.flip();
|
||||
|
||||
if(this.isInputBeingDecrypted){
|
||||
decryptedReadChunks.clear();
|
||||
|
||||
if (oldDecryptedChunkBuffer != null) {
|
||||
decryptedReadChunks.add(oldDecryptedChunkBuffer);
|
||||
oldDecryptedChunkBuffer = null;
|
||||
}
|
||||
|
||||
byte[] block = new byte[/*2048*/32];
|
||||
byte[] decryp = new byte[this.inputBufferedBlockCipher.getOutputSize(/*2048*/32)];
|
||||
while (stream.remaining() >= /*2048*/32) {
|
||||
stream.get(block);
|
||||
int i = this.inputBufferedBlockCipher.processByte(block, 0, /*2048*/32, decryp, 0);
|
||||
ByteBuffer chunk = ByteBuffer.allocate(i);
|
||||
chunk.put(decryp, 0, i);
|
||||
chunk.flip();
|
||||
decryptedReadChunks.add(chunk);
|
||||
}
|
||||
|
||||
oldChunkBuffer = stream.remaining() > 0 ? stream.slice() : null;
|
||||
|
||||
int cap2 = 0;
|
||||
for (ByteBuffer b : decryptedReadChunks) {
|
||||
cap2 += b.limit();
|
||||
}
|
||||
|
||||
ByteBuffer decStream = ByteBuffer.allocate(cap2);
|
||||
for (ByteBuffer b : decryptedReadChunks) {
|
||||
decStream.put(b);
|
||||
}
|
||||
decStream.flip();
|
||||
|
||||
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(decStream));
|
||||
while (decStream.hasRemaining()) {
|
||||
decStream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
if(logpackets)System.out.println("RECEIVING: " + pkt);
|
||||
pkt.processPacket(this.netHandler);
|
||||
} catch (EOFException e) {
|
||||
decStream.reset();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (decStream.hasRemaining()) {
|
||||
oldDecryptedChunkBuffer = decStream.slice();
|
||||
} else {
|
||||
oldDecryptedChunkBuffer = null;
|
||||
}
|
||||
}else {
|
||||
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream));
|
||||
while (stream.hasRemaining()) {
|
||||
stream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
boolean change=false;
|
||||
if (pkt != null) {
|
||||
if (Minecraft.getMinecraft().gameSettings.useDefaultProtocol && pkt instanceof Packet252SharedKey && !this.isInputBeingDecrypted) {
|
||||
packetStream = this.decryptInputStream(new ByteBufferDirectInputStream(stream));
|
||||
change=true;
|
||||
}
|
||||
if(logpackets)System.out.println("RECEIVING: " + pkt);
|
||||
pkt.processPacket(this.netHandler);
|
||||
if(change){
|
||||
processReadPackets();
|
||||
return;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
stream.reset();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (stream.hasRemaining()) {
|
||||
oldChunkBuffer = stream.slice();
|
||||
} else {
|
||||
oldChunkBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void serverShutdown() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
private DataInputStream decryptInputStream(ByteBufferDirectInputStream var1) throws IOException
|
||||
{
|
||||
this.isInputBeingDecrypted = true;
|
||||
if(this.inputBufferedBlockCipher==null){
|
||||
this.inputBufferedBlockCipher = CryptManager.createBufferedBlockCipher(false, (Key) this.sharedKeyForEncryption);
|
||||
}
|
||||
return new DataInputStream(CryptManager.decryptInputStream(this.inputBufferedBlockCipher, var1));
|
||||
}
|
||||
|
||||
/**
|
||||
* flushes the stream and replaces it with an encryptedOutputStream
|
||||
*/
|
||||
private DataOutputStream encryptOuputStream(DataOutputStream var0) throws IOException
|
||||
{
|
||||
var0.flush();
|
||||
this.isOutputEncrypted = true;
|
||||
BufferedOutputStream var1 = new BufferedOutputStream(CryptManager.encryptOuputStream(this.sharedKeyForEncryption, var0), 5120);
|
||||
return new DataOutputStream(var1);
|
||||
}
|
||||
private DataOutputStream encryptOuputStream() throws IOException
|
||||
{
|
||||
if(this.outputBufferedBlockCipher==null){
|
||||
this.outputBufferedBlockCipher = CryptManager.createBufferedBlockCipher(true, (Key) this.sharedKeyForEncryption);
|
||||
}
|
||||
BufferedOutputStream var1 = new BufferedOutputStream(CryptManager.encryptOuputStream(this.outputBufferedBlockCipher, sendBuffer), 5120);
|
||||
return new DataOutputStream(var1);
|
||||
}
|
||||
|
||||
public int packetSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void networkShutdown(String var1, Object... var2) {
|
||||
serverShutdown();
|
||||
}
|
||||
|
||||
public void closeConnections() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
89
src/lwjgl/java/net/minecraft/src/Packet252SharedKey.java
Normal file
89
src/lwjgl/java/net/minecraft/src/Packet252SharedKey.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class Packet252SharedKey extends Packet
|
||||
{
|
||||
private byte[] sharedSecret = new byte[0];
|
||||
private byte[] verifyToken = new byte[0];
|
||||
|
||||
/**
|
||||
* Secret AES key decrypted from sharedSecret via the server's private RSA key
|
||||
*/
|
||||
private SecretKey sharedKey;
|
||||
|
||||
public Packet252SharedKey() {}
|
||||
|
||||
public Packet252SharedKey(SecretKey par1SecretKey, PublicKey par2PublicKey, byte[] par3ArrayOfByte)
|
||||
{
|
||||
this.sharedKey = par1SecretKey;
|
||||
this.sharedSecret = CryptManager.encryptData(par2PublicKey, par1SecretKey.getEncoded());
|
||||
this.verifyToken = CryptManager.encryptData(par2PublicKey, par3ArrayOfByte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException
|
||||
{
|
||||
this.sharedSecret = readBytesFromStream(par1DataInputStream);
|
||||
this.verifyToken = readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
writeByteArray(par1DataOutputStream, this.sharedSecret);
|
||||
writeByteArray(par1DataOutputStream, this.verifyToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler)
|
||||
{
|
||||
par1NetHandler.handleSharedKey(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize()
|
||||
{
|
||||
return 2 + this.sharedSecret.length + 2 + this.verifyToken.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return secretKey, decrypting it from the sharedSecret byte array if needed
|
||||
*/
|
||||
public SecretKey getSharedKey(PrivateKey par1PrivateKey)
|
||||
{
|
||||
return par1PrivateKey == null ? this.sharedKey : (this.sharedKey = CryptManager.decryptSharedKey(par1PrivateKey, this.sharedSecret));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the secret AES sharedKey (used by client only)
|
||||
*/
|
||||
public SecretKey getSharedKey()
|
||||
{
|
||||
return this.getSharedKey(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return verifyToken
|
||||
*/
|
||||
public byte[] getVerifyToken(PrivateKey par1PrivateKey)
|
||||
{
|
||||
return par1PrivateKey == null ? this.verifyToken : CryptManager.decryptData(par1PrivateKey, this.verifyToken);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
public class Packet253ServerAuthData extends Packet
|
||||
{
|
||||
private String serverId;
|
||||
private PublicKey publicKey;
|
||||
private byte[] verifyToken = new byte[0];
|
||||
|
||||
public Packet253ServerAuthData() {}
|
||||
|
||||
public Packet253ServerAuthData(String par1Str, PublicKey par2PublicKey, byte[] par3ArrayOfByte)
|
||||
{
|
||||
this.serverId = par1Str;
|
||||
this.publicKey = par2PublicKey;
|
||||
this.verifyToken = par3ArrayOfByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException
|
||||
{
|
||||
this.serverId = readString(par1DataInputStream, 20);
|
||||
this.publicKey = CryptManager.decodePublicKey(readBytesFromStream(par1DataInputStream));
|
||||
this.verifyToken = readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
writeString(this.serverId, par1DataOutputStream);
|
||||
writeByteArray(par1DataOutputStream, this.publicKey.getEncoded());
|
||||
writeByteArray(par1DataOutputStream, this.verifyToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler)
|
||||
{
|
||||
par1NetHandler.handleServerAuthData(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize()
|
||||
{
|
||||
return 2 + this.serverId.length() * 2 + 2 + this.publicKey.getEncoded().length + 2 + this.verifyToken.length;
|
||||
}
|
||||
|
||||
public String getServerId()
|
||||
{
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
public PublicKey getPublicKey()
|
||||
{
|
||||
return this.publicKey;
|
||||
}
|
||||
|
||||
public byte[] getVerifyToken()
|
||||
{
|
||||
return this.verifyToken;
|
||||
}
|
||||
}
|
6
src/lwjgl/java/org/bouncycastle/asn1/ASN1Encodable.java
Normal file
6
src/lwjgl/java/org/bouncycastle/asn1/ASN1Encodable.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package org.bouncycastle.asn1;
|
||||
|
||||
public interface ASN1Encodable
|
||||
{
|
||||
ASN1Primitive toASN1Primitive();
|
||||
}
|
28
src/lwjgl/java/org/bouncycastle/asn1/ASN1Object.java
Normal file
28
src/lwjgl/java/org/bouncycastle/asn1/ASN1Object.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package org.bouncycastle.asn1;
|
||||
|
||||
public abstract class ASN1Object implements ASN1Encodable
|
||||
{
|
||||
public int hashCode()
|
||||
{
|
||||
return this.toASN1Primitive().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object par1Obj)
|
||||
{
|
||||
if (this == par1Obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!(par1Obj instanceof ASN1Encodable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASN1Encodable var2 = (ASN1Encodable)par1Obj;
|
||||
return this.toASN1Primitive().equals(var2.toASN1Primitive());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ASN1Primitive toASN1Primitive();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.bouncycastle.asn1;
|
||||
|
||||
public class ASN1ObjectIdentifier extends DERObjectIdentifier
|
||||
{
|
||||
public ASN1ObjectIdentifier(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
}
|
||||
|
||||
public ASN1ObjectIdentifier branch(String par1Str)
|
||||
{
|
||||
return new ASN1ObjectIdentifier(this.getId() + "." + par1Str);
|
||||
}
|
||||
}
|
18
src/lwjgl/java/org/bouncycastle/asn1/ASN1Primitive.java
Normal file
18
src/lwjgl/java/org/bouncycastle/asn1/ASN1Primitive.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package org.bouncycastle.asn1;
|
||||
|
||||
public abstract class ASN1Primitive extends ASN1Object
|
||||
{
|
||||
public final boolean equals(Object par1Obj)
|
||||
{
|
||||
return this == par1Obj ? true : par1Obj instanceof ASN1Encodable && this.asn1Equals(((ASN1Encodable)par1Obj).toASN1Primitive());
|
||||
}
|
||||
|
||||
public ASN1Primitive toASN1Primitive()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract int hashCode();
|
||||
|
||||
abstract boolean asn1Equals(ASN1Primitive var1);
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package org.bouncycastle.asn1;
|
||||
|
||||
public class DERObjectIdentifier extends ASN1Primitive
|
||||
{
|
||||
String identifier;
|
||||
private static ASN1ObjectIdentifier[][] cache = new ASN1ObjectIdentifier[255][];
|
||||
|
||||
public DERObjectIdentifier(String par1Str)
|
||||
{
|
||||
if (!isValidIdentifier(par1Str))
|
||||
{
|
||||
throw new IllegalArgumentException("string " + par1Str + " not an OID");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.identifier = par1Str;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return this.identifier.hashCode();
|
||||
}
|
||||
|
||||
boolean asn1Equals(ASN1Primitive par1ASN1Primitive)
|
||||
{
|
||||
return !(par1ASN1Primitive instanceof DERObjectIdentifier) ? false : this.identifier.equals(((DERObjectIdentifier)par1ASN1Primitive).identifier);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.getId();
|
||||
}
|
||||
|
||||
private static boolean isValidIdentifier(String par0Str)
|
||||
{
|
||||
if (par0Str.length() >= 3 && par0Str.charAt(1) == 46)
|
||||
{
|
||||
char var1 = par0Str.charAt(0);
|
||||
|
||||
if (var1 >= 48 && var1 <= 50)
|
||||
{
|
||||
boolean var2 = false;
|
||||
|
||||
for (int var3 = par0Str.length() - 1; var3 >= 2; --var3)
|
||||
{
|
||||
char var4 = par0Str.charAt(var3);
|
||||
|
||||
if (48 <= var4 && var4 <= 57)
|
||||
{
|
||||
var2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (var4 != 46)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!var2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var2 = false;
|
||||
}
|
||||
}
|
||||
|
||||
return var2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.bouncycastle.asn1.bc;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||
|
||||
public interface BCObjectIdentifiers
|
||||
{
|
||||
ASN1ObjectIdentifier bc = new ASN1ObjectIdentifier("1.3.6.1.4.1.22554");
|
||||
ASN1ObjectIdentifier bc_pbe = new ASN1ObjectIdentifier(bc.getId() + ".1");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1 = new ASN1ObjectIdentifier(bc_pbe.getId() + ".1");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256 = new ASN1ObjectIdentifier(bc_pbe.getId() + ".2.1");
|
||||
ASN1ObjectIdentifier bc_pbe_sha384 = new ASN1ObjectIdentifier(bc_pbe.getId() + ".2.2");
|
||||
ASN1ObjectIdentifier bc_pbe_sha512 = new ASN1ObjectIdentifier(bc_pbe.getId() + ".2.3");
|
||||
ASN1ObjectIdentifier bc_pbe_sha224 = new ASN1ObjectIdentifier(bc_pbe.getId() + ".2.4");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1_pkcs5 = new ASN1ObjectIdentifier(bc_pbe_sha1.getId() + ".1");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1_pkcs12 = new ASN1ObjectIdentifier(bc_pbe_sha1.getId() + ".2");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256_pkcs5 = new ASN1ObjectIdentifier(bc_pbe_sha256.getId() + ".1");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256_pkcs12 = new ASN1ObjectIdentifier(bc_pbe_sha256.getId() + ".2");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1_pkcs12_aes128_cbc = new ASN1ObjectIdentifier(bc_pbe_sha1_pkcs12.getId() + ".1.2");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1_pkcs12_aes192_cbc = new ASN1ObjectIdentifier(bc_pbe_sha1_pkcs12.getId() + ".1.22");
|
||||
ASN1ObjectIdentifier bc_pbe_sha1_pkcs12_aes256_cbc = new ASN1ObjectIdentifier(bc_pbe_sha1_pkcs12.getId() + ".1.42");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256_pkcs12_aes128_cbc = new ASN1ObjectIdentifier(bc_pbe_sha256_pkcs12.getId() + ".1.2");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256_pkcs12_aes192_cbc = new ASN1ObjectIdentifier(bc_pbe_sha256_pkcs12.getId() + ".1.22");
|
||||
ASN1ObjectIdentifier bc_pbe_sha256_pkcs12_aes256_cbc = new ASN1ObjectIdentifier(bc_pbe_sha256_pkcs12.getId() + ".1.42");
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package org.bouncycastle.asn1.pkcs;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||
|
||||
public interface PKCSObjectIdentifiers
|
||||
{
|
||||
ASN1ObjectIdentifier pkcs_1 = new ASN1ObjectIdentifier("1.2.840.113549.1.1");
|
||||
ASN1ObjectIdentifier rsaEncryption = pkcs_1.branch("1");
|
||||
ASN1ObjectIdentifier md2WithRSAEncryption = pkcs_1.branch("2");
|
||||
ASN1ObjectIdentifier md4WithRSAEncryption = pkcs_1.branch("3");
|
||||
ASN1ObjectIdentifier md5WithRSAEncryption = pkcs_1.branch("4");
|
||||
ASN1ObjectIdentifier sha1WithRSAEncryption = pkcs_1.branch("5");
|
||||
ASN1ObjectIdentifier srsaOAEPEncryptionSET = pkcs_1.branch("6");
|
||||
ASN1ObjectIdentifier id_RSAES_OAEP = pkcs_1.branch("7");
|
||||
ASN1ObjectIdentifier id_mgf1 = pkcs_1.branch("8");
|
||||
ASN1ObjectIdentifier id_pSpecified = pkcs_1.branch("9");
|
||||
ASN1ObjectIdentifier id_RSASSA_PSS = pkcs_1.branch("10");
|
||||
ASN1ObjectIdentifier sha256WithRSAEncryption = pkcs_1.branch("11");
|
||||
ASN1ObjectIdentifier sha384WithRSAEncryption = pkcs_1.branch("12");
|
||||
ASN1ObjectIdentifier sha512WithRSAEncryption = pkcs_1.branch("13");
|
||||
ASN1ObjectIdentifier sha224WithRSAEncryption = pkcs_1.branch("14");
|
||||
ASN1ObjectIdentifier pkcs_3 = new ASN1ObjectIdentifier("1.2.840.113549.1.3");
|
||||
ASN1ObjectIdentifier dhKeyAgreement = pkcs_3.branch("1");
|
||||
ASN1ObjectIdentifier pkcs_5 = new ASN1ObjectIdentifier("1.2.840.113549.1.5");
|
||||
ASN1ObjectIdentifier pbeWithMD2AndDES_CBC = pkcs_5.branch("1");
|
||||
ASN1ObjectIdentifier pbeWithMD2AndRC2_CBC = pkcs_5.branch("4");
|
||||
ASN1ObjectIdentifier pbeWithMD5AndDES_CBC = pkcs_5.branch("3");
|
||||
ASN1ObjectIdentifier pbeWithMD5AndRC2_CBC = pkcs_5.branch("6");
|
||||
ASN1ObjectIdentifier pbeWithSHA1AndDES_CBC = pkcs_5.branch("10");
|
||||
ASN1ObjectIdentifier pbeWithSHA1AndRC2_CBC = pkcs_5.branch("11");
|
||||
ASN1ObjectIdentifier id_PBES2 = pkcs_5.branch("13");
|
||||
ASN1ObjectIdentifier id_PBKDF2 = pkcs_5.branch("12");
|
||||
ASN1ObjectIdentifier encryptionAlgorithm = new ASN1ObjectIdentifier("1.2.840.113549.3");
|
||||
ASN1ObjectIdentifier des_EDE3_CBC = encryptionAlgorithm.branch("7");
|
||||
ASN1ObjectIdentifier RC2_CBC = encryptionAlgorithm.branch("2");
|
||||
ASN1ObjectIdentifier digestAlgorithm = new ASN1ObjectIdentifier("1.2.840.113549.2");
|
||||
ASN1ObjectIdentifier md2 = digestAlgorithm.branch("2");
|
||||
ASN1ObjectIdentifier md4 = digestAlgorithm.branch("4");
|
||||
ASN1ObjectIdentifier md5 = digestAlgorithm.branch("5");
|
||||
ASN1ObjectIdentifier id_hmacWithSHA1 = digestAlgorithm.branch("7");
|
||||
ASN1ObjectIdentifier id_hmacWithSHA224 = digestAlgorithm.branch("8");
|
||||
ASN1ObjectIdentifier id_hmacWithSHA256 = digestAlgorithm.branch("9");
|
||||
ASN1ObjectIdentifier id_hmacWithSHA384 = digestAlgorithm.branch("10");
|
||||
ASN1ObjectIdentifier id_hmacWithSHA512 = digestAlgorithm.branch("11");
|
||||
ASN1ObjectIdentifier data = new ASN1ObjectIdentifier("1.2.840.113549.1.7.1");
|
||||
ASN1ObjectIdentifier signedData = new ASN1ObjectIdentifier("1.2.840.113549.1.7.2");
|
||||
ASN1ObjectIdentifier envelopedData = new ASN1ObjectIdentifier("1.2.840.113549.1.7.3");
|
||||
ASN1ObjectIdentifier signedAndEnvelopedData = new ASN1ObjectIdentifier("1.2.840.113549.1.7.4");
|
||||
ASN1ObjectIdentifier digestedData = new ASN1ObjectIdentifier("1.2.840.113549.1.7.5");
|
||||
ASN1ObjectIdentifier encryptedData = new ASN1ObjectIdentifier("1.2.840.113549.1.7.6");
|
||||
ASN1ObjectIdentifier pkcs_9 = new ASN1ObjectIdentifier("1.2.840.113549.1.9");
|
||||
ASN1ObjectIdentifier pkcs_9_at_emailAddress = pkcs_9.branch("1");
|
||||
ASN1ObjectIdentifier pkcs_9_at_unstructuredName = pkcs_9.branch("2");
|
||||
ASN1ObjectIdentifier pkcs_9_at_contentType = pkcs_9.branch("3");
|
||||
ASN1ObjectIdentifier pkcs_9_at_messageDigest = pkcs_9.branch("4");
|
||||
ASN1ObjectIdentifier pkcs_9_at_signingTime = pkcs_9.branch("5");
|
||||
ASN1ObjectIdentifier pkcs_9_at_counterSignature = pkcs_9.branch("6");
|
||||
ASN1ObjectIdentifier pkcs_9_at_challengePassword = pkcs_9.branch("7");
|
||||
ASN1ObjectIdentifier pkcs_9_at_unstructuredAddress = pkcs_9.branch("8");
|
||||
ASN1ObjectIdentifier pkcs_9_at_extendedCertificateAttributes = pkcs_9.branch("9");
|
||||
ASN1ObjectIdentifier pkcs_9_at_signingDescription = pkcs_9.branch("13");
|
||||
ASN1ObjectIdentifier pkcs_9_at_extensionRequest = pkcs_9.branch("14");
|
||||
ASN1ObjectIdentifier pkcs_9_at_smimeCapabilities = pkcs_9.branch("15");
|
||||
ASN1ObjectIdentifier pkcs_9_at_friendlyName = pkcs_9.branch("20");
|
||||
ASN1ObjectIdentifier pkcs_9_at_localKeyId = pkcs_9.branch("21");
|
||||
ASN1ObjectIdentifier x509certType = pkcs_9.branch("22.1");
|
||||
ASN1ObjectIdentifier certTypes = pkcs_9.branch("22");
|
||||
ASN1ObjectIdentifier x509Certificate = certTypes.branch("1");
|
||||
ASN1ObjectIdentifier sdsiCertificate = certTypes.branch("2");
|
||||
ASN1ObjectIdentifier crlTypes = pkcs_9.branch("23");
|
||||
ASN1ObjectIdentifier x509Crl = crlTypes.branch("1");
|
||||
ASN1ObjectIdentifier id_alg_PWRI_KEK = pkcs_9.branch("16.3.9");
|
||||
ASN1ObjectIdentifier preferSignedData = pkcs_9.branch("15.1");
|
||||
ASN1ObjectIdentifier canNotDecryptAny = pkcs_9.branch("15.2");
|
||||
ASN1ObjectIdentifier sMIMECapabilitiesVersions = pkcs_9.branch("15.3");
|
||||
ASN1ObjectIdentifier id_ct = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.1");
|
||||
ASN1ObjectIdentifier id_ct_authData = id_ct.branch("2");
|
||||
ASN1ObjectIdentifier id_ct_TSTInfo = id_ct.branch("4");
|
||||
ASN1ObjectIdentifier id_ct_compressedData = id_ct.branch("9");
|
||||
ASN1ObjectIdentifier id_ct_authEnvelopedData = id_ct.branch("23");
|
||||
ASN1ObjectIdentifier id_ct_timestampedData = id_ct.branch("31");
|
||||
ASN1ObjectIdentifier id_cti = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.6");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfOrigin = id_cti.branch("1");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfReceipt = id_cti.branch("2");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfDelivery = id_cti.branch("3");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfSender = id_cti.branch("4");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfApproval = id_cti.branch("5");
|
||||
ASN1ObjectIdentifier id_cti_ets_proofOfCreation = id_cti.branch("6");
|
||||
ASN1ObjectIdentifier id_aa = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.2");
|
||||
ASN1ObjectIdentifier id_aa_receiptRequest = id_aa.branch("1");
|
||||
ASN1ObjectIdentifier id_aa_contentHint = id_aa.branch("4");
|
||||
ASN1ObjectIdentifier id_aa_msgSigDigest = id_aa.branch("5");
|
||||
ASN1ObjectIdentifier id_aa_contentReference = id_aa.branch("10");
|
||||
ASN1ObjectIdentifier id_aa_encrypKeyPref = id_aa.branch("11");
|
||||
ASN1ObjectIdentifier id_aa_signingCertificate = id_aa.branch("12");
|
||||
ASN1ObjectIdentifier id_aa_signingCertificateV2 = id_aa.branch("47");
|
||||
ASN1ObjectIdentifier id_aa_contentIdentifier = id_aa.branch("7");
|
||||
ASN1ObjectIdentifier id_aa_signatureTimeStampToken = id_aa.branch("14");
|
||||
ASN1ObjectIdentifier id_aa_ets_sigPolicyId = id_aa.branch("15");
|
||||
ASN1ObjectIdentifier id_aa_ets_commitmentType = id_aa.branch("16");
|
||||
ASN1ObjectIdentifier id_aa_ets_signerLocation = id_aa.branch("17");
|
||||
ASN1ObjectIdentifier id_aa_ets_signerAttr = id_aa.branch("18");
|
||||
ASN1ObjectIdentifier id_aa_ets_otherSigCert = id_aa.branch("19");
|
||||
ASN1ObjectIdentifier id_aa_ets_contentTimestamp = id_aa.branch("20");
|
||||
ASN1ObjectIdentifier id_aa_ets_certificateRefs = id_aa.branch("21");
|
||||
ASN1ObjectIdentifier id_aa_ets_revocationRefs = id_aa.branch("22");
|
||||
ASN1ObjectIdentifier id_aa_ets_certValues = id_aa.branch("23");
|
||||
ASN1ObjectIdentifier id_aa_ets_revocationValues = id_aa.branch("24");
|
||||
ASN1ObjectIdentifier id_aa_ets_escTimeStamp = id_aa.branch("25");
|
||||
ASN1ObjectIdentifier id_aa_ets_certCRLTimestamp = id_aa.branch("26");
|
||||
ASN1ObjectIdentifier id_aa_ets_archiveTimestamp = id_aa.branch("27");
|
||||
ASN1ObjectIdentifier id_aa_sigPolicyId = id_aa_ets_sigPolicyId;
|
||||
ASN1ObjectIdentifier id_aa_commitmentType = id_aa_ets_commitmentType;
|
||||
ASN1ObjectIdentifier id_aa_signerLocation = id_aa_ets_signerLocation;
|
||||
ASN1ObjectIdentifier id_aa_otherSigCert = id_aa_ets_otherSigCert;
|
||||
ASN1ObjectIdentifier id_spq_ets_uri = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.5.1");
|
||||
ASN1ObjectIdentifier id_spq_ets_unotice = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.5.2");
|
||||
ASN1ObjectIdentifier pkcs_12 = new ASN1ObjectIdentifier("1.2.840.113549.1.12");
|
||||
ASN1ObjectIdentifier bagtypes = pkcs_12.branch("10.1");
|
||||
ASN1ObjectIdentifier keyBag = bagtypes.branch("1");
|
||||
ASN1ObjectIdentifier pkcs8ShroudedKeyBag = bagtypes.branch("2");
|
||||
ASN1ObjectIdentifier certBag = bagtypes.branch("3");
|
||||
ASN1ObjectIdentifier crlBag = bagtypes.branch("4");
|
||||
ASN1ObjectIdentifier secretBag = bagtypes.branch("5");
|
||||
ASN1ObjectIdentifier safeContentsBag = bagtypes.branch("6");
|
||||
ASN1ObjectIdentifier pkcs_12PbeIds = pkcs_12.branch("1");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd128BitRC4 = pkcs_12PbeIds.branch("1");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd40BitRC4 = pkcs_12PbeIds.branch("2");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd3_KeyTripleDES_CBC = pkcs_12PbeIds.branch("3");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd2_KeyTripleDES_CBC = pkcs_12PbeIds.branch("4");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd128BitRC2_CBC = pkcs_12PbeIds.branch("5");
|
||||
ASN1ObjectIdentifier pbeWithSHAAnd40BitRC2_CBC = pkcs_12PbeIds.branch("6");
|
||||
ASN1ObjectIdentifier pbewithSHAAnd40BitRC2_CBC = pkcs_12PbeIds.branch("6");
|
||||
ASN1ObjectIdentifier id_alg_CMS3DESwrap = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.3.6");
|
||||
ASN1ObjectIdentifier id_alg_CMSRC2wrap = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.3.7");
|
||||
}
|
20
src/lwjgl/java/org/bouncycastle/crypto/BlockCipher.java
Normal file
20
src/lwjgl/java/org/bouncycastle/crypto/BlockCipher.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface BlockCipher
|
||||
{
|
||||
void init(boolean var1, CipherParameters var2) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
String getAlgorithmName();
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
int getBlockSize();
|
||||
|
||||
int processBlock(byte[] var1, int var2, byte[] var3, int var4) throws DataLengthException, IllegalStateException;
|
||||
|
||||
void reset();
|
||||
}
|
161
src/lwjgl/java/org/bouncycastle/crypto/BufferedBlockCipher.java
Normal file
161
src/lwjgl/java/org/bouncycastle/crypto/BufferedBlockCipher.java
Normal file
|
@ -0,0 +1,161 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class BufferedBlockCipher
|
||||
{
|
||||
protected byte[] buf;
|
||||
protected int bufOff;
|
||||
protected boolean forEncryption;
|
||||
protected BlockCipher cipher;
|
||||
protected boolean partialBlockOkay;
|
||||
protected boolean pgpCFB;
|
||||
|
||||
protected BufferedBlockCipher() {}
|
||||
|
||||
public BufferedBlockCipher(BlockCipher par1BlockCipher)
|
||||
{
|
||||
this.cipher = par1BlockCipher;
|
||||
this.buf = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.bufOff = 0;
|
||||
String var2 = par1BlockCipher.getAlgorithmName();
|
||||
int var3 = var2.indexOf(47) + 1;
|
||||
this.pgpCFB = var3 > 0 && var2.startsWith("PGP", var3);
|
||||
|
||||
if (this.pgpCFB)
|
||||
{
|
||||
this.partialBlockOkay = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.partialBlockOkay = var3 > 0 && (var2.startsWith("CFB", var3) || var2.startsWith("OFB", var3) || var2.startsWith("OpenPGP", var3) || var2.startsWith("SIC", var3) || var2.startsWith("GCTR", var3));
|
||||
}
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
this.forEncryption = par1;
|
||||
this.reset();
|
||||
this.cipher.init(par1, par2CipherParameters);
|
||||
}
|
||||
|
||||
public int getBlockSize()
|
||||
{
|
||||
return this.cipher.getBlockSize();
|
||||
}
|
||||
|
||||
public int getUpdateOutputSize(int par1)
|
||||
{
|
||||
int var2 = par1 + this.bufOff;
|
||||
int var3;
|
||||
|
||||
if (this.pgpCFB)
|
||||
{
|
||||
var3 = var2 % this.buf.length - (this.cipher.getBlockSize() + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var3 = var2 % this.buf.length;
|
||||
}
|
||||
|
||||
return var2 - var3;
|
||||
}
|
||||
|
||||
public int getOutputSize(int par1)
|
||||
{
|
||||
return par1 + this.bufOff;
|
||||
}
|
||||
|
||||
public int processByte(byte[] par1ArrayOfByte, int par2, int par3, byte[] par4ArrayOfByte, int par5) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par3 < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Can\'t have a negative input length!");
|
||||
}
|
||||
else
|
||||
{
|
||||
int var6 = this.getBlockSize();
|
||||
int var7 = this.getUpdateOutputSize(par3);
|
||||
|
||||
if (var7 > 0 && par5 + var7 > par4ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
int var8 = 0;
|
||||
int var9 = this.buf.length - this.bufOff;
|
||||
|
||||
if (par3 > var9)
|
||||
{
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.buf, this.bufOff, var9);
|
||||
var8 += this.cipher.processBlock(this.buf, 0, par4ArrayOfByte, par5);
|
||||
this.bufOff = 0;
|
||||
par3 -= var9;
|
||||
|
||||
for (par2 += var9; par3 > this.buf.length; par2 += var6)
|
||||
{
|
||||
var8 += this.cipher.processBlock(par1ArrayOfByte, par2, par4ArrayOfByte, par5 + var8);
|
||||
par3 -= var6;
|
||||
}
|
||||
}
|
||||
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.buf, this.bufOff, par3);
|
||||
this.bufOff += par3;
|
||||
|
||||
if (this.bufOff == this.buf.length)
|
||||
{
|
||||
var8 += this.cipher.processBlock(this.buf, 0, par4ArrayOfByte, par5 + var8);
|
||||
this.bufOff = 0;
|
||||
}
|
||||
|
||||
return var8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int doFinal(byte[] par1ArrayOfByte, int par2) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
int var4;
|
||||
|
||||
try
|
||||
{
|
||||
int var3 = 0;
|
||||
|
||||
if (par2 + this.bufOff > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short for doFinal()");
|
||||
}
|
||||
|
||||
if (this.bufOff != 0)
|
||||
{
|
||||
if (!this.partialBlockOkay)
|
||||
{
|
||||
throw new DataLengthException("data not block size aligned");
|
||||
}
|
||||
|
||||
this.cipher.processBlock(this.buf, 0, this.buf, 0);
|
||||
var3 = this.bufOff;
|
||||
this.bufOff = 0;
|
||||
System.arraycopy(this.buf, 0, par1ArrayOfByte, par2, var3);
|
||||
}
|
||||
|
||||
var4 = var3;
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.reset();
|
||||
}
|
||||
|
||||
return var4;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
for (int var1 = 0; var1 < this.buf.length; ++var1)
|
||||
{
|
||||
this.buf[var1] = 0;
|
||||
}
|
||||
|
||||
this.bufOff = 0;
|
||||
this.cipher.reset();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CipherKeyGenerator
|
||||
{
|
||||
protected Random random;
|
||||
protected int strength;
|
||||
|
||||
public void init(KeyGenerationParameters par1)
|
||||
{
|
||||
this.random = par1.getRandom();
|
||||
this.strength = (par1.getStrength() + 7) / 8;
|
||||
}
|
||||
|
||||
public byte[] generateKey()
|
||||
{
|
||||
byte[] var1 = new byte[this.strength];
|
||||
this.random.nextBytes(var1);
|
||||
return var1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface CipherParameters
|
||||
{
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class DataLengthException extends RuntimeCryptoException
|
||||
{
|
||||
public DataLengthException() {}
|
||||
|
||||
public DataLengthException(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class KeyGenerationParameters
|
||||
{
|
||||
private Random random;
|
||||
private int strength;
|
||||
|
||||
public KeyGenerationParameters(Random par1SecureRandom, int par2)
|
||||
{
|
||||
this.random = par1SecureRandom;
|
||||
this.strength = par2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the random source associated with this generator.
|
||||
*/
|
||||
public Random getRandom()
|
||||
{
|
||||
return this.random;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bit strength for keys produced by this generator.
|
||||
*/
|
||||
public int getStrength()
|
||||
{
|
||||
return this.strength;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class RuntimeCryptoException extends RuntimeException
|
||||
{
|
||||
public RuntimeCryptoException() {}
|
||||
|
||||
public RuntimeCryptoException(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
}
|
||||
}
|
11
src/lwjgl/java/org/bouncycastle/crypto/StreamCipher.java
Normal file
11
src/lwjgl/java/org/bouncycastle/crypto/StreamCipher.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface StreamCipher
|
||||
{
|
||||
/**
|
||||
* Encrypt/decrypt a single byte, returning the result.
|
||||
*/
|
||||
byte returnByte(byte var1);
|
||||
|
||||
void processBytes(byte[] var1, int var2, int var3, byte[] var4, int var5) throws DataLengthException;
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
package org.bouncycastle.crypto.engines;
|
||||
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
public class AESFastEngine implements BlockCipher
|
||||
{
|
||||
private static final byte[] S = new byte[] {(byte)99, (byte)124, (byte)119, (byte)123, (byte) - 14, (byte)107, (byte)111, (byte) - 59, (byte)48, (byte)1, (byte)103, (byte)43, (byte) - 2, (byte) - 41, (byte) - 85, (byte)118, (byte) - 54, (byte) - 126, (byte) - 55, (byte)125, (byte) - 6, (byte)89, (byte)71, (byte) - 16, (byte) - 83, (byte) - 44, (byte) - 94, (byte) - 81, (byte) - 100, (byte) - 92, (byte)114, (byte) - 64, (byte) - 73, (byte) - 3, (byte) - 109, (byte)38, (byte)54, (byte)63, (byte) - 9, (byte) - 52, (byte)52, (byte) - 91, (byte) - 27, (byte) - 15, (byte)113, (byte) - 40, (byte)49, (byte)21, (byte)4, (byte) - 57, (byte)35, (byte) - 61, (byte)24, (byte) - 106, (byte)5, (byte) - 102, (byte)7, (byte)18, (byte) - 128, (byte) - 30, (byte) - 21, (byte)39, (byte) - 78, (byte)117, (byte)9, (byte) - 125, (byte)44, (byte)26, (byte)27, (byte)110, (byte)90, (byte) - 96, (byte)82, (byte)59, (byte) - 42, (byte) - 77, (byte)41, (byte) - 29, (byte)47, (byte) - 124, (byte)83, (byte) - 47, (byte)0, (byte) - 19, (byte)32, (byte) - 4, (byte) - 79, (byte)91, (byte)106, (byte) - 53, (byte) - 66, (byte)57, (byte)74, (byte)76, (byte)88, (byte) - 49, (byte) - 48, (byte) - 17, (byte) - 86, (byte) - 5, (byte)67, (byte)77, (byte)51, (byte) - 123, (byte)69, (byte) - 7, (byte)2, (byte)127, (byte)80, (byte)60, (byte) - 97, (byte) - 88, (byte)81, (byte) - 93, (byte)64, (byte) - 113, (byte) - 110, (byte) - 99, (byte)56, (byte) - 11, (byte) - 68, (byte) - 74, (byte) - 38, (byte)33, (byte)16, (byte) - 1, (byte) - 13, (byte) - 46, (byte) - 51, (byte)12, (byte)19, (byte) - 20, (byte)95, (byte) - 105, (byte)68, (byte)23, (byte) - 60, (byte) - 89, (byte)126, (byte)61, (byte)100, (byte)93, (byte)25, (byte)115, (byte)96, (byte) - 127, (byte)79, (byte) - 36, (byte)34, (byte)42, (byte) - 112, (byte) - 120, (byte)70, (byte) - 18, (byte) - 72, (byte)20, (byte) - 34, (byte)94, (byte)11, (byte) - 37, (byte) - 32, (byte)50, (byte)58, (byte)10, (byte)73, (byte)6, (byte)36, (byte)92, (byte) - 62, (byte) - 45, (byte) - 84, (byte)98, (byte) - 111, (byte) - 107, (byte) - 28, (byte)121, (byte) - 25, (byte) - 56, (byte)55, (byte)109, (byte) - 115, (byte) - 43, (byte)78, (byte) - 87, (byte)108, (byte)86, (byte) - 12, (byte) - 22, (byte)101, (byte)122, (byte) - 82, (byte)8, (byte) - 70, (byte)120, (byte)37, (byte)46, (byte)28, (byte) - 90, (byte) - 76, (byte) - 58, (byte) - 24, (byte) - 35, (byte)116, (byte)31, (byte)75, (byte) - 67, (byte) - 117, (byte) - 118, (byte)112, (byte)62, (byte) - 75, (byte)102, (byte)72, (byte)3, (byte) - 10, (byte)14, (byte)97, (byte)53, (byte)87, (byte) - 71, (byte) - 122, (byte) - 63, (byte)29, (byte) - 98, (byte) - 31, (byte) - 8, (byte) - 104, (byte)17, (byte)105, (byte) - 39, (byte) - 114, (byte) - 108, (byte) - 101, (byte)30, (byte) - 121, (byte) - 23, (byte) - 50, (byte)85, (byte)40, (byte) - 33, (byte) - 116, (byte) - 95, (byte) - 119, (byte)13, (byte) - 65, (byte) - 26, (byte)66, (byte)104, (byte)65, (byte) - 103, (byte)45, (byte)15, (byte) - 80, (byte)84, (byte) - 69, (byte)22};
|
||||
private static final byte[] Si = new byte[] {(byte)82, (byte)9, (byte)106, (byte) - 43, (byte)48, (byte)54, (byte) - 91, (byte)56, (byte) - 65, (byte)64, (byte) - 93, (byte) - 98, (byte) - 127, (byte) - 13, (byte) - 41, (byte) - 5, (byte)124, (byte) - 29, (byte)57, (byte) - 126, (byte) - 101, (byte)47, (byte) - 1, (byte) - 121, (byte)52, (byte) - 114, (byte)67, (byte)68, (byte) - 60, (byte) - 34, (byte) - 23, (byte) - 53, (byte)84, (byte)123, (byte) - 108, (byte)50, (byte) - 90, (byte) - 62, (byte)35, (byte)61, (byte) - 18, (byte)76, (byte) - 107, (byte)11, (byte)66, (byte) - 6, (byte) - 61, (byte)78, (byte)8, (byte)46, (byte) - 95, (byte)102, (byte)40, (byte) - 39, (byte)36, (byte) - 78, (byte)118, (byte)91, (byte) - 94, (byte)73, (byte)109, (byte) - 117, (byte) - 47, (byte)37, (byte)114, (byte) - 8, (byte) - 10, (byte)100, (byte) - 122, (byte)104, (byte) - 104, (byte)22, (byte) - 44, (byte) - 92, (byte)92, (byte) - 52, (byte)93, (byte)101, (byte) - 74, (byte) - 110, (byte)108, (byte)112, (byte)72, (byte)80, (byte) - 3, (byte) - 19, (byte) - 71, (byte) - 38, (byte)94, (byte)21, (byte)70, (byte)87, (byte) - 89, (byte) - 115, (byte) - 99, (byte) - 124, (byte) - 112, (byte) - 40, (byte) - 85, (byte)0, (byte) - 116, (byte) - 68, (byte) - 45, (byte)10, (byte) - 9, (byte) - 28, (byte)88, (byte)5, (byte) - 72, (byte) - 77, (byte)69, (byte)6, (byte) - 48, (byte)44, (byte)30, (byte) - 113, (byte) - 54, (byte)63, (byte)15, (byte)2, (byte) - 63, (byte) - 81, (byte) - 67, (byte)3, (byte)1, (byte)19, (byte) - 118, (byte)107, (byte)58, (byte) - 111, (byte)17, (byte)65, (byte)79, (byte)103, (byte) - 36, (byte) - 22, (byte) - 105, (byte) - 14, (byte) - 49, (byte) - 50, (byte) - 16, (byte) - 76, (byte) - 26, (byte)115, (byte) - 106, (byte) - 84, (byte)116, (byte)34, (byte) - 25, (byte) - 83, (byte)53, (byte) - 123, (byte) - 30, (byte) - 7, (byte)55, (byte) - 24, (byte)28, (byte)117, (byte) - 33, (byte)110, (byte)71, (byte) - 15, (byte)26, (byte)113, (byte)29, (byte)41, (byte) - 59, (byte) - 119, (byte)111, (byte) - 73, (byte)98, (byte)14, (byte) - 86, (byte)24, (byte) - 66, (byte)27, (byte) - 4, (byte)86, (byte)62, (byte)75, (byte) - 58, (byte) - 46, (byte)121, (byte)32, (byte) - 102, (byte) - 37, (byte) - 64, (byte) - 2, (byte)120, (byte) - 51, (byte)90, (byte) - 12, (byte)31, (byte) - 35, (byte) - 88, (byte)51, (byte) - 120, (byte)7, (byte) - 57, (byte)49, (byte) - 79, (byte)18, (byte)16, (byte)89, (byte)39, (byte) - 128, (byte) - 20, (byte)95, (byte)96, (byte)81, (byte)127, (byte) - 87, (byte)25, (byte) - 75, (byte)74, (byte)13, (byte)45, (byte) - 27, (byte)122, (byte) - 97, (byte) - 109, (byte) - 55, (byte) - 100, (byte) - 17, (byte) - 96, (byte) - 32, (byte)59, (byte)77, (byte) - 82, (byte)42, (byte) - 11, (byte) - 80, (byte) - 56, (byte) - 21, (byte) - 69, (byte)60, (byte) - 125, (byte)83, (byte) - 103, (byte)97, (byte)23, (byte)43, (byte)4, (byte)126, (byte) - 70, (byte)119, (byte) - 42, (byte)38, (byte) - 31, (byte)105, (byte)20, (byte)99, (byte)85, (byte)33, (byte)12, (byte)125};
|
||||
private static final int[] rcon = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154, 47, 94, 188, 99, 198, 151, 53, 106, 212, 179, 125, 250, 239, 197, 145};
|
||||
private static final int[] T0 = new int[] { -1520213050, -2072216328, -1720223762, -1921287178, 234025727, -1117033514, -1318096930, 1422247313, 1345335392, 50397442, -1452841010, 2099981142, 436141799, 1658312629, -424957107, -1703512340, 1170918031, -1652391393, 1086966153, -2021818886, 368769775, -346465870, -918075506, 200339707, -324162239, 1742001331, -39673249, -357585083, -1080255453, -140204973, -1770884380, 1539358875, -1028147339, 486407649, -1366060227, 1780885068, 1513502316, 1094664062, 49805301, 1338821763, 1546925160, -190470831, 887481809, 150073849, -1821281822, 1943591083, 1395732834, 1058346282, 201589768, 1388824469, 1696801606, 1589887901, 672667696, -1583966665, 251987210, -1248159185, 151455502, 907153956, -1686077413, 1038279391, 652995533, 1764173646, -843926913, -1619692054, 453576978, -1635548387, 1949051992, 773462580, 756751158, -1301385508, -296068428, -73359269, -162377052, 1295727478, 1641469623, -827083907, 2066295122, 1055122397, 1898917726, -1752923117, -179088474, 1758581177, 0, 753790401, 1612718144, 536673507, -927878791, -312779850, -1100322092, 1187761037, -641810841, 1262041458, -565556588, -733197160, -396863312, 1255133061, 1808847035, 720367557, -441800113, 385612781, -985447546, -682799718, 1429418854, -1803188975, -817543798, 284817897, 100794884, -2122350594, -263171936, 1144798328, -1163944155, -475486133, -212774494, -22830243, -1069531008, -1970303227, -1382903233, -1130521311, 1211644016, 83228145, -541279133, -1044990345, 1977277103, 1663115586, 806359072, 452984805, 250868733, 1842533055, 1288555905, 336333848, 890442534, 804056259, -513843266, -1567123659, -867941240, 957814574, 1472513171, -223893675, -2105639172, 1195195770, -1402706744, -413311558, 723065138, -1787595802, -1604296512, -1736343271, -783331426, 2145180835, 1713513028, 2116692564, -1416589253, -2088204277, -901364084, 703524551, -742868885, 1007948840, 2044649127, -497131844, 487262998, 1994120109, 1004593371, 1446130276, 1312438900, 503974420, -615954030, 168166924, 1814307912, -463709000, 1573044895, 1859376061, -273896381, -1503501628, -1466855111, -1533700815, 937747667, -1954973198, 854058965, 1137232011, 1496790894, -1217565222, -1936880383, 1691735473, -766620004, -525751991, -1267962664, -95005012, 133494003, 636152527, -1352309302, -1904575756, -374428089, 403179536, -709182865, -2005370640, 1864705354, 1915629148, 605822008, -240736681, -944458637, 1371981463, 602466507, 2094914977, -1670089496, 555687742, -582268010, -591544991, -2037675251, -2054518257, -1871679264, 1111375484, -994724495, -1436129588, -666351472, 84083462, 32962295, 302911004, -1553899070, 1597322602, -111716434, -793134743, -1853454825, 1489093017, 656219450, -1180787161, 954327513, 335083755, -1281845205, 856756514, -1150719534, 1893325225, -1987146233, -1483434957, -1231316179, 572399164, -1836611819, 552200649, 1238290055, -11184726, 2015897680, 2061492133, -1886614525, -123625127, -2138470135, 386731290, -624967835, 837215959, -968736124, -1201116976, -1019133566, -1332111063, 1999449434, 286199582, -877612933, -61582168, -692339859, 974525996};
|
||||
private static final int[] T1 = new int[] {1667483301, 2088564868, 2004348569, 2071721613, -218956019, 1802229437, 1869602481, -976907948, 808476752, 16843267, 1734856361, 724260477, -16849127, -673729182, -1414836762, 1987505306, -892694715, -2105401443, -909539008, 2105408135, -84218091, 1499050731, 1195871945, -252642549, -1381154324, -724257945, -1566416899, -1347467798, -1667488833, -1532734473, 1920132246, -1061119141, -1212713534, -33693412, -1819066962, 640044138, 909536346, 1061125697, -134744830, -859012273, 875849820, -1515892236, -437923532, -235800312, 1903288979, -656888973, 825320019, 353708607, 67373068, -943221422, 589514341, -1010590370, 404238376, -1768540255, 84216335, -1701171275, 117902857, 303178806, -2139087973, -488448195, -336868058, 656887401, -1296924723, 1970662047, 151589403, -2088559202, 741103732, 437924910, 454768173, 1852759218, 1515893998, -1600103429, 1381147894, 993752653, -690571423, -1280082482, 690573947, -471605954, 791633521, -2071719017, 1397991157, -774784664, 0, -303185620, 538984544, -50535649, -1313769016, 1532737261, 1785386174, -875852474, -1094817831, 960066123, 1246401758, 1280088276, 1482207464, -808483510, -791626901, -269499094, -1431679003, -67375850, 1128498885, 1296931543, 859006549, -2054876780, 1162185423, -101062384, 33686534, 2139094657, 1347461360, 1010595908, -1616960070, -1465365533, 1364304627, -1549574658, 1077969088, -1886452342, -1835909203, -1650646596, 943222856, -168431356, -1128504353, -1229555775, -623202443, 555827811, 269492272, -6886, -202113778, -757940371, -842170036, 202119188, 320022069, -320027857, 1600110305, -1751698014, 1145342156, 387395129, -993750185, -1482205710, 2122251394, 1027439175, 1684326572, 1566423783, 421081643, 1936975509, 1616953504, -2122245736, 1330618065, -589520001, 572671078, 707417214, -1869595733, -2004350077, 1179028682, -286341335, -1195873325, 336865340, -555833479, 1583267042, 185275933, -606360202, -522134725, 842163286, 976909390, 168432670, 1229558491, 101059594, 606357612, 1549580516, -1027432611, -741098130, -1397996561, 1650640038, -1852753496, -1785384540, -454765769, 2038035083, -404237006, -926381245, 926379609, 1835915959, -1920138868, -707415708, 1313774802, -1448523296, 1819072692, 1448520954, -185273593, -353710299, 1701169839, 2054878350, -1364310039, 134746136, -1162186795, 2021191816, 623200879, 774790258, 471611428, -1499047951, -1263242297, -960063663, -387396829, -572677764, 1953818780, 522141217, 1263245021, -1111662116, -1953821306, -1970663547, 1886445712, 1044282434, -1246400060, 1718013098, 1212715224, 50529797, -151587071, 235805714, 1633796771, 892693087, 1465364217, -1179031088, -2038032495, -1044276904, 488454695, -1633802311, -505292488, -117904621, -1734857805, 286335539, 1768542907, -640046736, -1903294583, -1802226777, -1684329034, 505297954, -2021190254, -370554592, -825325751, 1431677695, 673730680, -538991238, -1936981105, -1583261192, -1987507840, 218962455, -1077975590, -421079247, 1111655622, 1751699640, 1094812355, -1718015568, 757946999, 252648977, -1330611253, 1414834428, -1145344554, 370551866};
|
||||
private static final int[] T2 = new int[] {1673962851, 2096661628, 2012125559, 2079755643, -218165774, 1809235307, 1876865391, -980331323, 811618352, 16909057, 1741597031, 727088427, -18408962, -675978537, -1420958037, 1995217526, -896580150, -2111857278, -913751863, 2113570685, -84994566, 1504897881, 1200539975, -251982864, -1388188499, -726439980, -1570767454, -1354372433, -1675378788, -1538000988, 1927583346, -1063560256, -1217019209, -35578627, -1824674157, 642542118, 913070646, 1065238847, -134937865, -863809588, 879254580, -1521355611, -439274267, -235337487, 1910674289, -659852328, 828527409, 355090197, 67636228, -946515257, 591815971, -1013096765, 405809176, -1774739050, 84545285, -1708149350, 118360327, 304363026, -2145674368, -488686110, -338876693, 659450151, -1300247118, 1978310517, 152181513, -2095210877, 743994412, 439627290, 456535323, 1859957358, 1521806938, -1604584544, 1386542674, 997608763, -692624938, -1283600717, 693271337, -472039709, 794718511, -2079090812, 1403450707, -776378159, 0, -306107155, 541089824, -52224004, -1317418831, 1538714971, 1792327274, -879933749, -1100490306, 963791673, 1251270218, 1285084236, 1487988824, -813348145, -793023536, -272291089, -1437604438, -68348165, 1132905795, 1301993293, 862344499, -2062445435, 1166724933, -102166279, 33818114, 2147385727, 1352724560, 1014514748, -1624917345, -1471421528, 1369633617, -1554121053, 1082179648, -1895462257, -1841320558, -1658733411, 946882616, -168753931, -1134305348, -1233665610, -626035238, 557998881, 270544912, -1762561, -201519373, -759206446, -847164211, 202904588, 321271059, -322752532, 1606345055, -1758092649, 1149815876, 388905239, -996976700, -1487539545, 2130477694, 1031423805, 1690872932, 1572530013, 422718233, 1944491379, 1623236704, -2129028991, 1335808335, -593264676, 574907938, 710180394, -1875137648, -2012511352, 1183631942, -288937490, -1200893000, 338181140, -559449634, 1589437022, 185998603, -609388837, -522503200, 845436466, 980700730, 169090570, 1234361161, 101452294, 608726052, 1555620956, -1029743166, -742560045, -1404833876, 1657054818, -1858492271, -1791908715, -455919644, 2045938553, -405458201, -930397240, 929978679, 1843050349, -1929278323, -709794603, 1318900302, -1454776151, 1826141292, 1454176854, -185399308, -355523094, 1707781989, 2062847610, -1371018834, 135272456, -1167075910, 2029029496, 625635109, 777810478, 473441308, -1504185946, -1267480652, -963161658, -389340184, -576619299, 1961401460, 524165407, 1268178251, -1117659971, -1962047861, -1978694262, 1893765232, 1048330814, -1250835275, 1724688998, 1217452104, 50726147, -151584266, 236720654, 1640145761, 896163637, 1471084887, -1184247623, -2045275770, -1046914879, 490350365, -1641563746, -505857823, -118811656, -1741966440, 287453969, 1775418217, -643206951, -1912108658, -1808554092, -1691502949, 507257374, -2028629369, -372694807, -829994546, 1437269845, 676362280, -542803233, -1945923700, -1587939167, -1995865975, 219813645, -1083843905, -422104602, 1115997762, 1758509160, 1099088705, -1725321063, 760903469, 253628687, -1334064208, 1420360788, -1150429509, 371997206};
|
||||
private static final int[] T3 = new int[] { -962239645, -125535108, -291932297, -158499973, -15863054, -692229269, -558796945, -1856715323, 1615867952, 33751297, -827758745, 1451043627, -417726722, -1251813417, 1306962859, -325421450, -1891251510, 530416258, -1992242743, -91783811, -283772166, -1293199015, -1899411641, -83103504, 1106029997, -1285040940, 1610457762, 1173008303, 599760028, 1408738468, -459902350, -1688485696, 1975695287, -518193667, 1034851219, 1282024998, 1817851446, 2118205247, -184354825, -2091922228, 1750873140, 1374987685, -785062427, -116854287, -493653647, -1418471208, 1649619249, 708777237, 135005188, -1789737017, 1181033251, -1654733885, 807933976, 933336726, 168756485, 800430746, 235472647, 607523346, 463175808, -549592350, -853087253, 1315514151, 2144187058, -358648459, 303761673, 496927619, 1484008492, 875436570, 908925723, -592286098, -1259447718, 1543217312, -1527360942, 1984772923, -1218324778, 2110698419, 1383803177, -583080989, 1584475951, 328696964, -1493871789, -1184312879, 0, -1054020115, 1080041504, -484442884, 2043195825, -1225958565, -725718422, -1924740149, 1742323390, 1917532473, -1797371318, -1730917300, -1326950312, -2058694705, -1150562096, -987041809, 1340451498, -317260805, -2033892541, -1697166003, 1716859699, 294946181, -1966127803, -384763399, 67502594, -25067649, -1594863536, 2017737788, 632987551, 1273211048, -1561112239, 1576969123, -2134884288, 92966799, 1068339858, 566009245, 1883781176, -251333131, 1675607228, 2009183926, -1351230758, 1113792801, 540020752, -451215361, -49351693, -1083321646, -2125673011, 403966988, 641012499, -1020269332, -1092526241, 899848087, -1999879100, 775493399, -1822964540, 1441965991, -58556802, 2051489085, -928226204, -1159242403, 841685273, -426413197, -1063231392, 429425025, -1630449841, -1551901476, 1147544098, 1417554474, 1001099408, 193169544, -1932900794, -953553170, 1809037496, 675025940, -1485185314, -1126015394, 371002123, -1384719397, -616832800, 1683370546, 1951283770, 337512970, -1831122615, 201983494, 1215046692, -1192993700, -1621245246, -1116810285, 1139780780, -995728798, 967348625, 832869781, -751311644, -225740423, -718084121, -1958491960, 1851340599, -625513107, 25988493, -1318791723, -1663938994, 1239460265, -659264404, -1392880042, -217582348, -819598614, -894474907, -191989126, 1206496942, 270010376, 1876277946, -259491720, 1248797989, 1550986798, 941890588, 1475454630, 1942467764, -1756248378, -886839064, -1585652259, -392399756, 1042358047, -1763882165, 1641856445, 226921355, 260409994, -527404944, 2084716094, 1908716981, -861247898, -1864873912, 100991747, -150866186, 470945294, -1029480095, 1784624437, -1359390889, 1775286713, 395413126, -1722236479, 975641885, 666476190, -650583583, -351012616, 733190296, 573772049, -759469719, -1452221991, 126455438, 866620564, 766942107, 1008868894, 361924487, -920589847, -2025206066, -1426107051, 1350051880, -1518673953, 59739276, 1509466529, 159418761, 437718285, 1708834751, -684595482, -2067381694, -793221016, -2101132991, 699439513, 1517759789, 504434447, 2076946608, -1459858348, 1842789307, 742004246};
|
||||
private static final int[] Tinv0 = new int[] {1353184337, 1399144830, -1012656358, -1772214470, -882136261, -247096033, -1420232020, -1828461749, 1442459680, -160598355, -1854485368, 625738485, -52959921, -674551099, -2143013594, -1885117771, 1230680542, 1729870373, -1743852987, -507445667, 41234371, 317738113, -1550367091, -956705941, -413167869, -1784901099, -344298049, -631680363, 763608788, -752782248, 694804553, 1154009486, 1787413109, 2021232372, 1799248025, -579749593, -1236278850, 397248752, 1722556617, -1271214467, 407560035, -2110711067, 1613975959, 1165972322, -529046351, -2068943941, 480281086, -1809118983, 1483229296, 436028815, -2022908268, -1208452270, 601060267, -503166094, 1468997603, 715871590, 120122290, 63092015, -1703164538, -1526188077, -226023376, -1297760477, -1167457534, 1552029421, 723308426, -1833666137, -252573709, -1578997426, -839591323, -708967162, 526529745, -1963022652, -1655493068, -1604979806, 853641733, 1978398372, 971801355, -1427152832, 111112542, 1360031421, -108388034, 1023860118, -1375387939, 1186850381, -1249028975, 90031217, 1876166148, -15380384, 620468249, -1746289194, -868007799, 2006899047, -1119688528, -2004121337, 945494503, -605108103, 1191869601, -384875908, -920746760, 0, -2088337399, 1223502642, -1401941730, 1316117100, -67170563, 1446544655, 517320253, 658058550, 1691946762, 564550760, -783000677, 976107044, -1318647284, 266819475, -761860428, -1634624741, 1338359936, -1574904735, 1766553434, 370807324, 179999714, -450191168, 1138762300, 488053522, 185403662, -1379431438, -1180125651, -928440812, -2061897385, 1275557295, -1143105042, -44007517, -1624899081, -1124765092, -985962940, 880737115, 1982415755, -590994485, 1761406390, 1676797112, -891538985, 277177154, 1076008723, 538035844, 2099530373, -130171950, 288553390, 1839278535, 1261411869, -214912292, -330136051, -790380169, 1813426987, -1715900247, -95906799, 577038663, -997393240, 440397984, -668172970, -275762398, -951170681, -1043253031, -22885748, 906744984, -813566554, 685669029, 646887386, -1530942145, -459458004, 227702864, -1681105046, 1648787028, -1038905866, -390539120, 1593260334, -173030526, -1098883681, 2090061929, -1456614033, -1290656305, 999926984, -1484974064, 1852021992, 2075868123, 158869197, -199730834, 28809964, -1466282109, 1701746150, 2129067946, 147831841, -420997649, -644094022, -835293366, -737566742, -696471511, -1347247055, 824393514, 815048134, -1067015627, 935087732, -1496677636, -1328508704, 366520115, 1251476721, -136647615, 240176511, 804688151, -1915335306, 1303441219, 1414376140, -553347356, -474623586, 461924940, -1205916479, 2136040774, 82468509, 1563790337, 1937016826, 776014843, 1511876531, 1389550482, 861278441, 323475053, -1939744870, 2047648055, -1911228327, -1992551445, -299390514, 902390199, -303751967, 1018251130, 1507840668, 1064563285, 2043548696, -1086863501, -355600557, 1537932639, 342834655, -2032450440, -2114736182, 1053059257, 741614648, 1598071746, 1925389590, 203809468, -1958134744, 1100287487, 1895934009, -558691320, -1662733096, -1866377628, 1636092795, 1890988757, 1952214088, 1113045200};
|
||||
private static final int[] Tinv1 = new int[] { -1477160624, 1698790995, -1541989693, 1579629206, 1806384075, 1167925233, 1492823211, 65227667, -97509291, 1836494326, 1993115793, 1275262245, -672837636, -886389289, 1144333952, -1553812081, 1521606217, 465184103, 250234264, -1057071647, 1966064386, -263421678, -1756983901, -103584826, 1603208167, -1668147819, 2054012907, 1498584538, -2084645843, 561273043, 1776306473, -926314940, -1983744662, 2039411832, 1045993835, 1907959773, 1340194486, -1383534569, -1407137434, 986611124, 1256153880, 823846274, 860985184, 2136171077, 2003087840, -1368671356, -1602093540, 722008468, 1749577816, -45773031, 1826526343, -126135625, -747394269, 38499042, -1893735593, -1420466646, 686535175, -1028313341, 2076542618, 137876389, -2027409166, -1514200142, 1778582202, -2112426660, 483363371, -1267095662, -234359824, -496415071, -187013683, -1106966827, 1647628575, -22625142, 1395537053, 1442030240, -511048398, -336157579, -326956231, -278904662, -1619960314, 275692881, -1977532679, 115185213, 88006062, -1108980410, -1923837515, 1573155077, -737803153, 357589247, -73918172, -373434729, 1128303052, -1629919369, 1122545853, -1953953912, 1528424248, -288851493, 175939911, 256015593, 512030921, 0, -2038429309, -315936184, 1880170156, 1918528590, -15794693, 948244310, -710001378, 959264295, -653325724, -1503893471, 1415289809, 775300154, 1728711857, -413691121, -1762741038, -1852105826, -977239985, 551313826, 1266113129, 437394454, -1164713462, 715178213, -534627261, 387650077, 218697227, -947129683, -1464455751, -1457646392, 435246981, 125153100, -577114437, 1618977789, 637663135, -177054532, 996558021, 2130402100, 692292470, -970732580, -51530136, -236668829, -600713270, -2057092592, 580326208, 298222624, 608863613, 1035719416, 855223825, -1591097491, 798891339, 817028339, 1384517100, -473860144, 380840812, -1183798887, 1217663482, 1693009698, -1929598780, 1072734234, 746411736, -1875696913, 1313441735, -784803391, -1563783938, 198481974, -2114607409, -562387672, -1900553690, -1079165020, -1657131804, -1837608947, -866162021, 1182684258, 328070850, -1193766680, -147247522, -1346141451, -2141347906, -1815058052, 768962473, 304467891, -1716729797, 2098729127, 1671227502, -1153705093, 2015808777, 408514292, -1214583807, -1706064984, 1855317605, -419452290, -809754360, -401215514, -1679312167, 913263310, 161475284, 2091919830, -1297862225, 591342129, -1801075152, 1721906624, -1135709129, -897385306, -795811664, -660131051, -1744506550, -622050825, 1355644686, -158263505, -699566451, -1326496947, 1303039060, 76997855, -1244553501, -2006299621, 523026872, 1365591679, -362898172, 898367837, 1955068531, 1091304238, 493335386, -757362094, 1443948851, 1205234963, 1641519756, 211892090, 351820174, 1007938441, 665439982, -916342987, -451091987, -1320715716, -539845543, 1945261375, -837543815, 935818175, -839429142, -1426235557, 1866325780, -616269690, -206583167, -999769794, 874788908, 1084473951, -1021503886, 635616268, 1228679307, -1794244799, 27801969, -1291056930, -457910116, -1051302768, -2067039391, -1238182544, 1550600308, 1471729730};
|
||||
private static final int[] Tinv2 = new int[] { -195997529, 1098797925, 387629988, 658151006, -1422144661, -1658851003, -89347240, -481586429, 807425530, 1991112301, -863465098, 49620300, -447742761, 717608907, 891715652, 1656065955, -1310832294, -1171953893, -364537842, -27401792, 801309301, 1283527408, 1183687575, -747911431, -1895569569, -1844079204, 1841294202, 1385552473, -1093390973, 1951978273, -532076183, -913423160, -1032492407, -1896580999, 1486449470, -1188569743, -507595185, -1997531219, 550069932, -830622662, -547153846, 451248689, 1368875059, 1398949247, 1689378935, 1807451310, -2114052960, 150574123, 1215322216, 1167006205, -560691348, 2069018616, 1940595667, 1265820162, 534992783, 1432758955, -340654296, -1255210046, -981034373, 936617224, 674296455, -1088179547, 50510442, 384654466, -813028580, 2041025204, 133427442, 1766760930, -630862348, 84334014, 886120290, -1497068802, 775200083, -207445931, -1979370783, -156994069, -2096416276, 1614850799, 1901987487, 1857900816, 557775242, -577356538, 1054715397, -431143235, 1418835341, -999226019, 100954068, 1348534037, -1743182597, -1110009879, 1082772547, -647530594, -391070398, -1995994997, 434583643, -931537938, 2090944266, 1115482383, -2064070370, 0, -2146860154, 724715757, 287222896, 1517047410, 251526143, -2062592456, -1371726123, 758523705, 252339417, 1550328230, 1536938324, 908343854, 168604007, 1469255655, -290139498, -1692688751, -1065332795, -597581280, 2002413899, 303830554, -1813902662, -1597971158, 574374880, 454171927, 151915277, -1947030073, -1238517336, 504678569, -245922535, 1974422535, -1712407587, 2141453664, 33005350, 1918680309, 1715782971, -77908866, 1133213225, 600562886, -306812676, -457677839, 836225756, 1665273989, -1760346078, -964419567, 1250262308, -1143801795, -106032846, 700935585, -1642247377, -1294142672, -2045907886, -1049112349, -1288999914, 1890163129, -1810761144, -381214108, -56048500, -257942977, 2102843436, 857927568, 1233635150, 953795025, -896729438, -728222197, -173617279, 2057644254, -1210440050, -1388337985, 976020637, 2018512274, 1600822220, 2119459398, -1913208301, -661591880, 959340279, -1014827601, 1570750080, -798393197, -714102483, 634368786, -1396163687, 403744637, -1662488989, 1004239803, 650971512, 1500443672, -1695809097, 1334028442, -1780062866, -5603610, -1138685745, 368043752, -407184997, 1867173430, -1612000247, -1339435396, -1540247630, 1059729699, -1513738092, -1573535642, 1316239292, -2097371446, -1864322864, -1489824296, 82922136, -331221030, -847311280, -1860751370, 1299615190, -280801872, -1429449651, -1763385596, -778116171, 1783372680, 750893087, 1699118929, 1587348714, -1946067659, -2013629580, 201010753, 1739807261, -611167534, 283718486, -697494713, -677737375, -1590199796, -128348652, 334203196, -1446056409, 1639396809, 484568549, 1199193265, -761505313, -229294221, 337148366, -948715721, -145495347, -44082262, 1038029935, 1148749531, -1345682957, 1756970692, 607661108, -1547542720, 488010435, -490992603, 1009290057, 234832277, -1472630527, 201907891, -1260872476, 1449431233, -881106556, 852848822, 1816687708, -1194311081};
|
||||
private static final int[] Tinv3 = new int[] {1364240372, 2119394625, 449029143, 982933031, 1003187115, 535905693, -1398056710, 1267925987, 542505520, -1376359050, -2003732788, -182105086, 1341970405, -975713494, 645940277, -1248877726, -565617999, 627514298, 1167593194, 1575076094, -1023249105, -2129465268, -1918658746, 1808202195, 65494927, 362126482, -1075086739, -1780852398, -735214658, 1490231668, 1227450848, -1908094775, 1969916354, -193431154, -1721024936, 668823993, -1095348255, -266883704, -916018144, 2108963534, 1662536415, -444452582, -1755303087, 1648721747, -1310689436, -1148932501, -31678335, -107730168, 1884842056, -1894122171, -1803064098, 1387788411, -1423715469, 1927414347, -480800993, 1714072405, -1308153621, 788775605, -2036696123, -744159177, 821200680, 598910399, 45771267, -312704490, -1976886065, -1483557767, -202313209, 1319232105, 1707996378, 114671109, -786472396, -997523802, 882725678, -1566550541, 87220618, -1535775754, 188345475, 1084944224, 1577492337, -1118760850, 1056541217, -1774385443, -575797954, 1296481766, -1850372780, 1896177092, 74437638, 1627329872, 421854104, -694687299, -1983102144, 1735892697, -1329773848, 126389129, -415737063, 2044456648, -1589179780, 2095648578, -121037180, 0, 159614592, 843640107, 514617361, 1817080410, -33816818, 257308805, 1025430958, 908540205, 174381327, 1747035740, -1680780197, 607792694, 212952842, -1827674281, -1261267218, 463376795, -2142255680, 1638015196, 1516850039, 471210514, -502613357, -1058723168, 1011081250, 303896347, 235605257, -223492213, 767142070, 348694814, 1468340721, -1353971851, -289677927, -1543675777, -140564991, 1555887474, 1153776486, 1530167035, -1955190461, -874723805, -1234633491, -1201409564, -674571215, 1108378979, 322970263, -2078273082, -2055396278, -755483205, -1374604551, -949116631, 491466654, -588042062, 233591430, 2010178497, 728503987, -1449543312, 301615252, 1193436393, -1463513860, -1608892432, 1457007741, 586125363, -2016981431, -641609416, -1929469238, -1741288492, -1496350219, -1524048262, -635007305, 1067761581, 753179962, 1343066744, 1788595295, 1415726718, -155053171, -1863796520, 777975609, -2097827901, -1614905251, 1769771984, 1873358293, -810347995, -935618132, 279411992, -395418724, -612648133, -855017434, 1861490777, -335431782, -2086102449, -429560171, -1434523905, 554225596, -270079979, -1160143897, 1255028335, -355202657, 701922480, 833598116, 707863359, -969894747, 901801634, 1949809742, -56178046, -525283184, 857069735, -246769660, 1106762476, 2131644621, 389019281, 1989006925, 1129165039, -866890326, -455146346, -1629243951, 1276872810, -1044898004, 1182749029, -1660622242, 22885772, -93096825, -80854773, -1285939865, -1840065829, -382511600, 1829980118, -1702075945, 930745505, 1502483704, -343327725, -823253079, -1221211807, -504503012, 2050797895, -1671831598, 1430221810, 410635796, 1941911495, 1407897079, 1599843069, -552308931, 2022103876, -897453137, -1187068824, 942421028, -1033944925, 376619805, -1140054558, 680216892, -12479219, 963707304, 148812556, -660806476, 1687208278, 2069988555, -714033614, 1215585388, -800958536};
|
||||
private int ROUNDS;
|
||||
private int[][] WorkingKey = (int[][])null;
|
||||
private int C0;
|
||||
private int C1;
|
||||
private int C2;
|
||||
private int C3;
|
||||
private boolean forEncryption;
|
||||
|
||||
private int shift(int par1, int par2)
|
||||
{
|
||||
return par1 >>> par2 | par1 << -par2;
|
||||
}
|
||||
|
||||
private int FFmulX(int par1)
|
||||
{
|
||||
return (par1 & 2139062143) << 1 ^ ((par1 & -2139062144) >>> 7) * 27;
|
||||
}
|
||||
|
||||
private int inv_mcol(int par1)
|
||||
{
|
||||
int var2 = this.FFmulX(par1);
|
||||
int var3 = this.FFmulX(var2);
|
||||
int var4 = this.FFmulX(var3);
|
||||
int var5 = par1 ^ var4;
|
||||
return var2 ^ var3 ^ var4 ^ this.shift(var2 ^ var5, 8) ^ this.shift(var3 ^ var5, 16) ^ this.shift(var5, 24);
|
||||
}
|
||||
|
||||
private int subWord(int par1)
|
||||
{
|
||||
return S[par1 & 255] & 255 | (S[par1 >> 8 & 255] & 255) << 8 | (S[par1 >> 16 & 255] & 255) << 16 | S[par1 >> 24 & 255] << 24;
|
||||
}
|
||||
|
||||
private int[][] generateWorkingKey(byte[] par1ArrayOfByte, boolean par2)
|
||||
{
|
||||
int var3 = par1ArrayOfByte.length / 4;
|
||||
|
||||
if ((var3 == 4 || var3 == 6 || var3 == 8) && var3 * 4 == par1ArrayOfByte.length)
|
||||
{
|
||||
this.ROUNDS = var3 + 6;
|
||||
int[][] var5 = new int[this.ROUNDS + 1][4];
|
||||
int var4 = 0;
|
||||
int var6;
|
||||
|
||||
for (var6 = 0; var6 < par1ArrayOfByte.length; ++var4)
|
||||
{
|
||||
var5[var4 >> 2][var4 & 3] = par1ArrayOfByte[var6] & 255 | (par1ArrayOfByte[var6 + 1] & 255) << 8 | (par1ArrayOfByte[var6 + 2] & 255) << 16 | par1ArrayOfByte[var6 + 3] << 24;
|
||||
var6 += 4;
|
||||
}
|
||||
|
||||
int var7 = this.ROUNDS + 1 << 2;
|
||||
int var8;
|
||||
|
||||
for (var6 = var3; var6 < var7; ++var6)
|
||||
{
|
||||
var8 = var5[var6 - 1 >> 2][var6 - 1 & 3];
|
||||
|
||||
if (var6 % var3 == 0)
|
||||
{
|
||||
var8 = this.subWord(this.shift(var8, 8)) ^ rcon[var6 / var3 - 1];
|
||||
}
|
||||
else if (var3 > 6 && var6 % var3 == 4)
|
||||
{
|
||||
var8 = this.subWord(var8);
|
||||
}
|
||||
|
||||
var5[var6 >> 2][var6 & 3] = var5[var6 - var3 >> 2][var6 - var3 & 3] ^ var8;
|
||||
}
|
||||
|
||||
if (!par2)
|
||||
{
|
||||
for (var8 = 1; var8 < this.ROUNDS; ++var8)
|
||||
{
|
||||
for (var6 = 0; var6 < 4; ++var6)
|
||||
{
|
||||
var5[var8][var6] = this.inv_mcol(var5[var8][var6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return var5;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Key length not 128/192/256 bits.");
|
||||
}
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
if (par2CipherParameters instanceof KeyParameter)
|
||||
{
|
||||
this.WorkingKey = this.generateWorkingKey(((KeyParameter)par2CipherParameters).getKey(), par1);
|
||||
this.forEncryption = par1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("invalid parameter passed to AES init - " + par2CipherParameters.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
public String getAlgorithmName()
|
||||
{
|
||||
return "AES";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
public int getBlockSize()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public int processBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (this.WorkingKey == null)
|
||||
{
|
||||
throw new IllegalStateException("AES engine not initialised");
|
||||
}
|
||||
else if (par2 + 16 > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + 16 > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.forEncryption)
|
||||
{
|
||||
this.unpackBlock(par1ArrayOfByte, par2);
|
||||
this.encryptBlock(this.WorkingKey);
|
||||
this.packBlock(par3ArrayOfByte, par4);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.unpackBlock(par1ArrayOfByte, par2);
|
||||
this.decryptBlock(this.WorkingKey);
|
||||
this.packBlock(par3ArrayOfByte, par4);
|
||||
}
|
||||
|
||||
return 16;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {}
|
||||
|
||||
private void unpackBlock(byte[] par1ArrayOfByte, int par2)
|
||||
{
|
||||
int var3 = par2 + 1;
|
||||
this.C0 = par1ArrayOfByte[par2] & 255;
|
||||
this.C0 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C0 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C0 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C1 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C1 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C1 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C1 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C2 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C2 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C2 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C2 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C3 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C3 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C3 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C3 |= par1ArrayOfByte[var3++] << 24;
|
||||
}
|
||||
|
||||
private void packBlock(byte[] par1ArrayOfByte, int par2)
|
||||
{
|
||||
int var3 = par2 + 1;
|
||||
par1ArrayOfByte[par2] = (byte)this.C0;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C1;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C2;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C3;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 24);
|
||||
}
|
||||
|
||||
private void encryptBlock(int[][] par1ArrayOfInteger)
|
||||
{
|
||||
this.C0 ^= par1ArrayOfInteger[0][0];
|
||||
this.C1 ^= par1ArrayOfInteger[0][1];
|
||||
this.C2 ^= par1ArrayOfInteger[0][2];
|
||||
this.C3 ^= par1ArrayOfInteger[0][3];
|
||||
int var2;
|
||||
int var3;
|
||||
int var4;
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var2 = 1; var2 < this.ROUNDS - 1; this.C3 = T0[var6 & 255] ^ T1[var3 >> 8 & 255] ^ T2[var4 >> 16 & 255] ^ T3[var5 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3])
|
||||
{
|
||||
var3 = T0[this.C0 & 255] ^ T1[this.C1 >> 8 & 255] ^ T2[this.C2 >> 16 & 255] ^ T3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
var4 = T0[this.C1 & 255] ^ T1[this.C2 >> 8 & 255] ^ T2[this.C3 >> 16 & 255] ^ T3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
var5 = T0[this.C2 & 255] ^ T1[this.C3 >> 8 & 255] ^ T2[this.C0 >> 16 & 255] ^ T3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
var6 = T0[this.C3 & 255] ^ T1[this.C0 >> 8 & 255] ^ T2[this.C1 >> 16 & 255] ^ T3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3];
|
||||
this.C0 = T0[var3 & 255] ^ T1[var4 >> 8 & 255] ^ T2[var5 >> 16 & 255] ^ T3[var6 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
this.C1 = T0[var4 & 255] ^ T1[var5 >> 8 & 255] ^ T2[var6 >> 16 & 255] ^ T3[var3 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
this.C2 = T0[var5 & 255] ^ T1[var6 >> 8 & 255] ^ T2[var3 >> 16 & 255] ^ T3[var4 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
}
|
||||
|
||||
var3 = T0[this.C0 & 255] ^ T1[this.C1 >> 8 & 255] ^ T2[this.C2 >> 16 & 255] ^ T3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
var4 = T0[this.C1 & 255] ^ T1[this.C2 >> 8 & 255] ^ T2[this.C3 >> 16 & 255] ^ T3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
var5 = T0[this.C2 & 255] ^ T1[this.C3 >> 8 & 255] ^ T2[this.C0 >> 16 & 255] ^ T3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
var6 = T0[this.C3 & 255] ^ T1[this.C0 >> 8 & 255] ^ T2[this.C1 >> 16 & 255] ^ T3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3];
|
||||
this.C0 = S[var3 & 255] & 255 ^ (S[var4 >> 8 & 255] & 255) << 8 ^ (S[var5 >> 16 & 255] & 255) << 16 ^ S[var6 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][0];
|
||||
this.C1 = S[var4 & 255] & 255 ^ (S[var5 >> 8 & 255] & 255) << 8 ^ (S[var6 >> 16 & 255] & 255) << 16 ^ S[var3 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][1];
|
||||
this.C2 = S[var5 & 255] & 255 ^ (S[var6 >> 8 & 255] & 255) << 8 ^ (S[var3 >> 16 & 255] & 255) << 16 ^ S[var4 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][2];
|
||||
this.C3 = S[var6 & 255] & 255 ^ (S[var3 >> 8 & 255] & 255) << 8 ^ (S[var4 >> 16 & 255] & 255) << 16 ^ S[var5 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][3];
|
||||
}
|
||||
|
||||
private void decryptBlock(int[][] par1ArrayOfInteger)
|
||||
{
|
||||
this.C0 ^= par1ArrayOfInteger[this.ROUNDS][0];
|
||||
this.C1 ^= par1ArrayOfInteger[this.ROUNDS][1];
|
||||
this.C2 ^= par1ArrayOfInteger[this.ROUNDS][2];
|
||||
this.C3 ^= par1ArrayOfInteger[this.ROUNDS][3];
|
||||
int var2;
|
||||
int var3;
|
||||
int var4;
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var6 = this.ROUNDS - 1; var6 > 1; this.C3 = Tinv0[var5 & 255] ^ Tinv1[var4 >> 8 & 255] ^ Tinv2[var3 >> 16 & 255] ^ Tinv3[var2 >> 24 & 255] ^ par1ArrayOfInteger[var6--][3])
|
||||
{
|
||||
var2 = Tinv0[this.C0 & 255] ^ Tinv1[this.C3 >> 8 & 255] ^ Tinv2[this.C2 >> 16 & 255] ^ Tinv3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
var3 = Tinv0[this.C1 & 255] ^ Tinv1[this.C0 >> 8 & 255] ^ Tinv2[this.C3 >> 16 & 255] ^ Tinv3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
var4 = Tinv0[this.C2 & 255] ^ Tinv1[this.C1 >> 8 & 255] ^ Tinv2[this.C0 >> 16 & 255] ^ Tinv3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
var5 = Tinv0[this.C3 & 255] ^ Tinv1[this.C2 >> 8 & 255] ^ Tinv2[this.C1 >> 16 & 255] ^ Tinv3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var6--][3];
|
||||
this.C0 = Tinv0[var2 & 255] ^ Tinv1[var5 >> 8 & 255] ^ Tinv2[var4 >> 16 & 255] ^ Tinv3[var3 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
this.C1 = Tinv0[var3 & 255] ^ Tinv1[var2 >> 8 & 255] ^ Tinv2[var5 >> 16 & 255] ^ Tinv3[var4 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
this.C2 = Tinv0[var4 & 255] ^ Tinv1[var3 >> 8 & 255] ^ Tinv2[var2 >> 16 & 255] ^ Tinv3[var5 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
}
|
||||
|
||||
var2 = Tinv0[this.C0 & 255] ^ Tinv1[this.C3 >> 8 & 255] ^ Tinv2[this.C2 >> 16 & 255] ^ Tinv3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
var3 = Tinv0[this.C1 & 255] ^ Tinv1[this.C0 >> 8 & 255] ^ Tinv2[this.C3 >> 16 & 255] ^ Tinv3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
var4 = Tinv0[this.C2 & 255] ^ Tinv1[this.C1 >> 8 & 255] ^ Tinv2[this.C0 >> 16 & 255] ^ Tinv3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
var5 = Tinv0[this.C3 & 255] ^ Tinv1[this.C2 >> 8 & 255] ^ Tinv2[this.C1 >> 16 & 255] ^ Tinv3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var6][3];
|
||||
this.C0 = Si[var2 & 255] & 255 ^ (Si[var5 >> 8 & 255] & 255) << 8 ^ (Si[var4 >> 16 & 255] & 255) << 16 ^ Si[var3 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][0];
|
||||
this.C1 = Si[var3 & 255] & 255 ^ (Si[var2 >> 8 & 255] & 255) << 8 ^ (Si[var5 >> 16 & 255] & 255) << 16 ^ Si[var4 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][1];
|
||||
this.C2 = Si[var4 & 255] & 255 ^ (Si[var3 >> 8 & 255] & 255) << 8 ^ (Si[var2 >> 16 & 255] & 255) << 16 ^ Si[var5 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][2];
|
||||
this.C3 = Si[var5 & 255] & 255 ^ (Si[var4 >> 8 & 255] & 255) << 8 ^ (Si[var3 >> 16 & 255] & 255) << 16 ^ Si[var2 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][3];
|
||||
}
|
||||
}
|
178
src/lwjgl/java/org/bouncycastle/crypto/io/CipherInputStream.java
Normal file
178
src/lwjgl/java/org/bouncycastle/crypto/io/CipherInputStream.java
Normal file
|
@ -0,0 +1,178 @@
|
|||
package org.bouncycastle.crypto.io;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
|
||||
public class CipherInputStream extends FilterInputStream
|
||||
{
|
||||
private BufferedBlockCipher theBufferedBlockCipher;
|
||||
private StreamCipher theStreamCipher;
|
||||
private byte[] buf;
|
||||
private byte[] inBuf;
|
||||
private int bufOff;
|
||||
private int maxBuf;
|
||||
private boolean finalized;
|
||||
|
||||
public CipherInputStream(InputStream par1InputStream, BufferedBlockCipher par2BufferedBlockCipher)
|
||||
{
|
||||
super(par1InputStream);
|
||||
this.theBufferedBlockCipher = par2BufferedBlockCipher;
|
||||
this.buf = new byte[par2BufferedBlockCipher.getOutputSize(2048)];
|
||||
this.inBuf = new byte[2048];
|
||||
}
|
||||
|
||||
private int nextChunk() throws IOException
|
||||
{
|
||||
int var1 = super.available();
|
||||
|
||||
if (var1 <= 0)
|
||||
{
|
||||
var1 = 1;
|
||||
}
|
||||
|
||||
if (var1 > this.inBuf.length)
|
||||
{
|
||||
var1 = super.read(this.inBuf, 0, this.inBuf.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
var1 = super.read(this.inBuf, 0, var1);
|
||||
}
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
if (this.finalized)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
this.maxBuf = this.theBufferedBlockCipher.doFinal(this.buf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.maxBuf = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception var4)
|
||||
{
|
||||
throw new IOException("error processing stream: " + var4.toString());
|
||||
}
|
||||
|
||||
this.bufOff = 0;
|
||||
this.finalized = true;
|
||||
|
||||
if (this.bufOff == this.maxBuf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bufOff = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
this.maxBuf = this.theBufferedBlockCipher.processByte(this.inBuf, 0, var1, this.buf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theStreamCipher.processBytes(this.inBuf, 0, var1, this.buf, 0);
|
||||
this.maxBuf = var1;
|
||||
}
|
||||
}
|
||||
catch (Exception var3)
|
||||
{
|
||||
throw new IOException("error processing stream: " + var3.toString());
|
||||
}
|
||||
|
||||
if (this.maxBuf == 0)
|
||||
{
|
||||
return this.nextChunk();
|
||||
}
|
||||
}
|
||||
|
||||
return this.maxBuf;
|
||||
}
|
||||
|
||||
public int read() throws IOException
|
||||
{
|
||||
return this.bufOff == this.maxBuf && this.nextChunk() < 0 ? -1 : this.buf[this.bufOff++] & 255;
|
||||
}
|
||||
|
||||
public int read(byte[] par1ArrayOfByte) throws IOException
|
||||
{
|
||||
return this.read(par1ArrayOfByte, 0, par1ArrayOfByte.length);
|
||||
}
|
||||
|
||||
public int read(byte[] par1ArrayOfByte, int par2, int par3) throws IOException
|
||||
{
|
||||
if (this.bufOff == this.maxBuf && this.nextChunk() < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int var4 = this.maxBuf - this.bufOff;
|
||||
|
||||
if (par3 > var4)
|
||||
{
|
||||
System.arraycopy(this.buf, this.bufOff, par1ArrayOfByte, par2, var4);
|
||||
this.bufOff = this.maxBuf;
|
||||
return var4;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.arraycopy(this.buf, this.bufOff, par1ArrayOfByte, par2, par3);
|
||||
this.bufOff += par3;
|
||||
return par3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long skip(long par1) throws IOException
|
||||
{
|
||||
if (par1 <= 0L)
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
int var3 = this.maxBuf - this.bufOff;
|
||||
|
||||
if (par1 > (long)var3)
|
||||
{
|
||||
this.bufOff = this.maxBuf;
|
||||
return (long)var3;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bufOff += (int)par1;
|
||||
return (long)((int)par1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException
|
||||
{
|
||||
return this.maxBuf - this.bufOff;
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
super.close();
|
||||
}
|
||||
|
||||
public boolean markSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package org.bouncycastle.crypto.io;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
|
||||
public class CipherOutputStream extends FilterOutputStream
|
||||
{
|
||||
private BufferedBlockCipher theBufferedBlockCipher;
|
||||
private StreamCipher theStreamCipher;
|
||||
private byte[] oneByte = new byte[1];
|
||||
private byte[] buf;
|
||||
|
||||
public CipherOutputStream(OutputStream par1OutputStream, BufferedBlockCipher par2BufferedBlockCipher)
|
||||
{
|
||||
super(par1OutputStream);
|
||||
this.theBufferedBlockCipher = par2BufferedBlockCipher;
|
||||
this.buf = new byte[par2BufferedBlockCipher.getBlockSize()];
|
||||
}
|
||||
|
||||
public void write(int par1) throws IOException
|
||||
{
|
||||
this.oneByte[0] = (byte)par1;
|
||||
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
int var2 = this.theBufferedBlockCipher.processByte(this.oneByte, 0, 1, this.buf, 0);
|
||||
|
||||
if (var2 != 0)
|
||||
{
|
||||
this.out.write(this.buf, 0, var2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.out.write(this.theStreamCipher.returnByte((byte)par1));
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] par1) throws IOException
|
||||
{
|
||||
this.write(par1, 0, par1.length);
|
||||
}
|
||||
|
||||
public void write(byte[] par1, int par2, int par3) throws IOException
|
||||
{
|
||||
byte[] var4;
|
||||
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
var4 = new byte[this.theBufferedBlockCipher.getOutputSize(par3)];
|
||||
int var5 = this.theBufferedBlockCipher.processByte(par1, par2, par3, var4, 0);
|
||||
|
||||
if (var5 != 0)
|
||||
{
|
||||
this.out.write(var4, 0, var5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var4 = new byte[par3];
|
||||
this.theStreamCipher.processBytes(par1, par2, par3, var4, 0);
|
||||
this.out.write(var4, 0, par3);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException
|
||||
{
|
||||
super.flush();
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
byte[] var1 = new byte[this.theBufferedBlockCipher.getOutputSize(0)];
|
||||
int var2 = this.theBufferedBlockCipher.doFinal(var1, 0);
|
||||
|
||||
if (var2 != 0)
|
||||
{
|
||||
this.out.write(var1, 0, var2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception var3)
|
||||
{
|
||||
throw new IOException("Error closing stream: " + var3.toString());
|
||||
}
|
||||
|
||||
this.flush();
|
||||
super.close();
|
||||
}
|
||||
}
|
139
src/lwjgl/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java
Normal file
139
src/lwjgl/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
package org.bouncycastle.crypto.modes;
|
||||
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
public class CFBBlockCipher implements BlockCipher
|
||||
{
|
||||
private byte[] IV;
|
||||
private byte[] cfbV;
|
||||
private byte[] cfbOutV;
|
||||
private int blockSize;
|
||||
private BlockCipher cipher = null;
|
||||
private boolean encrypting;
|
||||
|
||||
public CFBBlockCipher(BlockCipher par1BlockCipher, int par2)
|
||||
{
|
||||
this.cipher = par1BlockCipher;
|
||||
this.blockSize = par2 / 8;
|
||||
this.IV = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.cfbV = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.cfbOutV = new byte[par1BlockCipher.getBlockSize()];
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
this.encrypting = par1;
|
||||
|
||||
if (par2CipherParameters instanceof ParametersWithIV)
|
||||
{
|
||||
ParametersWithIV var3 = (ParametersWithIV)par2CipherParameters;
|
||||
byte[] var4 = var3.getIV();
|
||||
|
||||
if (var4.length < this.IV.length)
|
||||
{
|
||||
System.arraycopy(var4, 0, this.IV, this.IV.length - var4.length, var4.length);
|
||||
|
||||
for (int var5 = 0; var5 < this.IV.length - var4.length; ++var5)
|
||||
{
|
||||
this.IV[var5] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.arraycopy(var4, 0, this.IV, 0, this.IV.length);
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
if (var3.getParameters() != null)
|
||||
{
|
||||
this.cipher.init(true, var3.getParameters());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.reset();
|
||||
this.cipher.init(true, par2CipherParameters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
public String getAlgorithmName()
|
||||
{
|
||||
return this.cipher.getAlgorithmName() + "/CFB" + this.blockSize * 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
public int getBlockSize()
|
||||
{
|
||||
return this.blockSize;
|
||||
}
|
||||
|
||||
public int processBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
return this.encrypting ? this.encryptBlock(par1ArrayOfByte, par2, par3ArrayOfByte, par4) : this.decryptBlock(par1ArrayOfByte, par2, par3ArrayOfByte, par4);
|
||||
}
|
||||
|
||||
public int encryptBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par2 + this.blockSize > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + this.blockSize > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cipher.processBlock(this.cfbV, 0, this.cfbOutV, 0);
|
||||
|
||||
for (int var5 = 0; var5 < this.blockSize; ++var5)
|
||||
{
|
||||
par3ArrayOfByte[par4 + var5] = (byte)(this.cfbOutV[var5] ^ par1ArrayOfByte[par2 + var5]);
|
||||
}
|
||||
|
||||
System.arraycopy(this.cfbV, this.blockSize, this.cfbV, 0, this.cfbV.length - this.blockSize);
|
||||
System.arraycopy(par3ArrayOfByte, par4, this.cfbV, this.cfbV.length - this.blockSize, this.blockSize);
|
||||
return this.blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public int decryptBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par2 + this.blockSize > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + this.blockSize > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cipher.processBlock(this.cfbV, 0, this.cfbOutV, 0);
|
||||
System.arraycopy(this.cfbV, this.blockSize, this.cfbV, 0, this.cfbV.length - this.blockSize);
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.cfbV, this.cfbV.length - this.blockSize, this.blockSize);
|
||||
|
||||
for (int var5 = 0; var5 < this.blockSize; ++var5)
|
||||
{
|
||||
par3ArrayOfByte[par4 + var5] = (byte)(this.cfbOutV[var5] ^ par1ArrayOfByte[par2 + var5]);
|
||||
}
|
||||
|
||||
return this.blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
System.arraycopy(this.IV, 0, this.cfbV, 0, this.IV.length);
|
||||
this.cipher.reset();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class KeyParameter implements CipherParameters
|
||||
{
|
||||
private byte[] key;
|
||||
|
||||
public KeyParameter(byte[] par1ArrayOfByte)
|
||||
{
|
||||
this(par1ArrayOfByte, 0, par1ArrayOfByte.length);
|
||||
}
|
||||
|
||||
public KeyParameter(byte[] par1ArrayOfByte, int par2, int par3)
|
||||
{
|
||||
this.key = new byte[par3];
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.key, 0, par3);
|
||||
}
|
||||
|
||||
public byte[] getKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class ParametersWithIV implements CipherParameters
|
||||
{
|
||||
private byte[] iv;
|
||||
private CipherParameters parameters;
|
||||
|
||||
public ParametersWithIV(CipherParameters par1CipherParameters, byte[] par2ArrayOfByte, int par3, int par4)
|
||||
{
|
||||
this.iv = new byte[par4];
|
||||
this.parameters = par1CipherParameters;
|
||||
System.arraycopy(par2ArrayOfByte, par3, this.iv, 0, par4);
|
||||
}
|
||||
|
||||
public byte[] getIV()
|
||||
{
|
||||
return this.iv;
|
||||
}
|
||||
|
||||
public CipherParameters getParameters()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bouncycastle.jcajce.provider.config;
|
||||
|
||||
public interface ConfigurableProvider
|
||||
{
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bouncycastle.jcajce.provider.config;
|
||||
|
||||
public interface ProviderConfiguration
|
||||
{
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package org.bouncycastle.jcajce.provider.config;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
import java.security.Permission;
|
||||
import java.util.StringTokenizer;
|
||||
import org.bouncycastle.util.Strings;
|
||||
|
||||
public class ProviderConfigurationPermission extends BasicPermission
|
||||
{
|
||||
private final String actions;
|
||||
private final int permissionMask;
|
||||
|
||||
public ProviderConfigurationPermission(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
this.actions = "all";
|
||||
this.permissionMask = 15;
|
||||
}
|
||||
|
||||
public ProviderConfigurationPermission(String par1Str, String par2Str)
|
||||
{
|
||||
super(par1Str, par2Str);
|
||||
this.actions = par2Str;
|
||||
this.permissionMask = this.calculateMask(par2Str);
|
||||
}
|
||||
|
||||
private int calculateMask(String par1Str)
|
||||
{
|
||||
StringTokenizer var2 = new StringTokenizer(Strings.toLowerCase(par1Str), " ,");
|
||||
int var3 = 0;
|
||||
|
||||
while (var2.hasMoreTokens())
|
||||
{
|
||||
String var4 = var2.nextToken();
|
||||
|
||||
if (var4.equals("threadlocalecimplicitlyca"))
|
||||
{
|
||||
var3 |= 1;
|
||||
}
|
||||
else if (var4.equals("ecimplicitlyca"))
|
||||
{
|
||||
var3 |= 2;
|
||||
}
|
||||
else if (var4.equals("threadlocaldhdefaultparams"))
|
||||
{
|
||||
var3 |= 4;
|
||||
}
|
||||
else if (var4.equals("dhdefaultparams"))
|
||||
{
|
||||
var3 |= 8;
|
||||
}
|
||||
else if (var4.equals("all"))
|
||||
{
|
||||
var3 |= 15;
|
||||
}
|
||||
}
|
||||
|
||||
if (var3 == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("unknown permissions passed to mask");
|
||||
}
|
||||
else
|
||||
{
|
||||
return var3;
|
||||
}
|
||||
}
|
||||
|
||||
public String getActions()
|
||||
{
|
||||
return this.actions;
|
||||
}
|
||||
|
||||
public boolean implies(Permission par1Permission)
|
||||
{
|
||||
if (!(par1Permission instanceof ProviderConfigurationPermission))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!this.getName().equals(par1Permission.getName()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ProviderConfigurationPermission var2 = (ProviderConfigurationPermission)par1Permission;
|
||||
return (this.permissionMask & var2.permissionMask) == var2.permissionMask;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object par1Obj)
|
||||
{
|
||||
if (par1Obj == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!(par1Obj instanceof ProviderConfigurationPermission))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ProviderConfigurationPermission var2 = (ProviderConfigurationPermission)par1Obj;
|
||||
return this.permissionMask == var2.permissionMask && this.getName().equals(var2.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return this.getName().hashCode() + this.permissionMask;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.bouncycastle.jcajce.provider.util;
|
||||
|
||||
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
|
||||
|
||||
public abstract class AlgorithmProvider
|
||||
{
|
||||
public abstract void configure(ConfigurableProvider var1);
|
||||
}
|
|
@ -0,0 +1,314 @@
|
|||
package org.bouncycastle.jce.provider;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.Provider;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bouncycastle.asn1.bc.BCObjectIdentifiers;
|
||||
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
|
||||
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
|
||||
import org.bouncycastle.jcajce.provider.config.ProviderConfiguration;
|
||||
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
|
||||
|
||||
public final class BouncyCastleProvider extends Provider implements ConfigurableProvider
|
||||
{
|
||||
private static String info = "BouncyCastle Security Provider v1.47";
|
||||
public static String PROVIDER_NAME = "BC";
|
||||
public static final ProviderConfiguration CONFIGURATION = new BouncyCastleProviderConfiguration();
|
||||
private static final Map keyInfoConverters = new HashMap();
|
||||
private static final String[] SYMMETRIC_CIPHERS = new String[] {"AES", "ARC4", "Blowfish", "Camellia", "CAST5", "CAST6", "DES", "DESede", "GOST28147", "Grainv1", "Grain128", "HC128", "HC256", "IDEA", "Noekeon", "RC2", "RC5", "RC6", "Rijndael", "Salsa20", "SEED", "Serpent", "Skipjack", "TEA", "Twofish", "VMPC", "VMPCKSA3", "XTEA"};
|
||||
private static final String[] ASYMMETRIC_GENERIC = new String[] {"X509"};
|
||||
private static final String[] ASYMMETRIC_CIPHERS = new String[] {"DSA", "DH", "EC", "RSA", "GOST", "ECGOST", "ElGamal"};
|
||||
private static final String[] DIGESTS = new String[] {"GOST3411", "MD2", "MD4", "MD5", "SHA1", "RIPEMD128", "RIPEMD160", "RIPEMD256", "RIPEMD320", "SHA224", "SHA256", "SHA384", "SHA512", "Tiger", "Whirlpool"};
|
||||
|
||||
public BouncyCastleProvider()
|
||||
{
|
||||
super(PROVIDER_NAME, 1.47D, info);
|
||||
AccessController.doPrivileged(new BouncyCastleProviderAction(this));
|
||||
}
|
||||
|
||||
private void setup()
|
||||
{
|
||||
this.loadAlgorithms("org.bouncycastle.jcajce.provider.digest.", DIGESTS);
|
||||
this.loadAlgorithms("org.bouncycastle.jcajce.provider.symmetric.", SYMMETRIC_CIPHERS);
|
||||
this.loadAlgorithms("org.bouncycastle.jcajce.provider.asymmetric.", ASYMMETRIC_GENERIC);
|
||||
this.loadAlgorithms("org.bouncycastle.jcajce.provider.asymmetric.", ASYMMETRIC_CIPHERS);
|
||||
this.put("X509Store.CERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertCollection");
|
||||
this.put("X509Store.ATTRIBUTECERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreAttrCertCollection");
|
||||
this.put("X509Store.CRL/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCRLCollection");
|
||||
this.put("X509Store.CERTIFICATEPAIR/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertPairCollection");
|
||||
this.put("X509Store.CERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCerts");
|
||||
this.put("X509Store.CRL/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCRLs");
|
||||
this.put("X509Store.ATTRIBUTECERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPAttrCerts");
|
||||
this.put("X509Store.CERTIFICATEPAIR/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCertPairs");
|
||||
this.put("X509StreamParser.CERTIFICATE", "org.bouncycastle.jce.provider.X509CertParser");
|
||||
this.put("X509StreamParser.ATTRIBUTECERTIFICATE", "org.bouncycastle.jce.provider.X509AttrCertParser");
|
||||
this.put("X509StreamParser.CRL", "org.bouncycastle.jce.provider.X509CRLParser");
|
||||
this.put("X509StreamParser.CERTIFICATEPAIR", "org.bouncycastle.jce.provider.X509CertPairParser");
|
||||
this.put("KeyStore.BKS", "org.bouncycastle.jce.provider.JDKKeyStore");
|
||||
this.put("KeyStore.BouncyCastle", "org.bouncycastle.jce.provider.JDKKeyStore$BouncyCastleStore");
|
||||
this.put("KeyStore.PKCS12", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
|
||||
this.put("KeyStore.BCPKCS12", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
|
||||
this.put("KeyStore.PKCS12-DEF", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
|
||||
this.put("KeyStore.PKCS12-3DES-40RC2", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore");
|
||||
this.put("KeyStore.PKCS12-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore3DES");
|
||||
this.put("KeyStore.PKCS12-DEF-3DES-40RC2", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore");
|
||||
this.put("KeyStore.PKCS12-DEF-3DES-3DES", "org.bouncycastle.jce.provider.JDKPKCS12KeyStore$DefPKCS12KeyStore3DES");
|
||||
this.put("Alg.Alias.KeyStore.UBER", "BouncyCastle");
|
||||
this.put("Alg.Alias.KeyStore.BOUNCYCASTLE", "BouncyCastle");
|
||||
this.put("Alg.Alias.KeyStore.bouncycastle", "BouncyCastle");
|
||||
this.put("AlgorithmParameters.IES", "org.bouncycastle.jce.provider.JDKAlgorithmParameters$IES");
|
||||
this.put("AlgorithmParameters.PKCS12PBE", "org.bouncycastle.jce.provider.JDKAlgorithmParameters$PKCS12PBE");
|
||||
this.put("AlgorithmParameters." + PKCSObjectIdentifiers.id_PBKDF2, "org.bouncycastle.jce.provider.JDKAlgorithmParameters$PBKDF2");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND3-KEYTRIPLEDES", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND2-KEYTRIPLEDES", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC2", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC4", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES3KEY-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDDES2KEY-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC2-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC4", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC2-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC4", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDTWOFISH-CBC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.1", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.2", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.3", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.4", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.5", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.6", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWithSHAAnd3KeyTripleDES", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.getId(), "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND192BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND256BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND128BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND192BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND256BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND128BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND192BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND256BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND128BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND192BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND256BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND128BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND192BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND256BITAES-CBC-BC", "PKCS12PBE");
|
||||
this.put("AlgorithmParameters.SHA1WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
|
||||
this.put("AlgorithmParameters.SHA224WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
|
||||
this.put("AlgorithmParameters.SHA256WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
|
||||
this.put("AlgorithmParameters.SHA384WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
|
||||
this.put("AlgorithmParameters.SHA512WITHECDSA", "org.bouncycastle.jce.provider.JDKECDSAAlgParameters$SigAlgParameters");
|
||||
this.put("Alg.Alias.Cipher.PBEWithSHAAnd3KeyTripleDES", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
|
||||
this.put("Cipher.ECIES", "org.bouncycastle.jce.provider.JCEIESCipher$ECIES");
|
||||
this.put("Cipher.BrokenECIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenECIES");
|
||||
this.put("Cipher.IES", "org.bouncycastle.jce.provider.JCEIESCipher$IES");
|
||||
this.put("Cipher.BrokenIES", "org.bouncycastle.jce.provider.JCEIESCipher$BrokenIES");
|
||||
this.put("Cipher.PBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithMD5AndDES");
|
||||
this.put("Cipher.BROKENPBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithMD5AndDES");
|
||||
this.put("Cipher.PBEWITHMD5ANDRC2", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithMD5AndRC2");
|
||||
this.put("Cipher.PBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHA1AndDES");
|
||||
this.put("Cipher.BROKENPBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithSHA1AndDES");
|
||||
this.put("Cipher.PBEWITHSHA1ANDRC2", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHA1AndRC2");
|
||||
this.put("Cipher.PBEWITHSHAAND128BITRC2-CBC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHAAnd128BitRC2");
|
||||
this.put("Cipher.PBEWITHSHAAND40BITRC2-CBC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHAAnd40BitRC2");
|
||||
this.put("Cipher.PBEWITHSHAAND128BITRC4", "org.bouncycastle.jce.provider.JCEStreamCipher$PBEWithSHAAnd128BitRC4");
|
||||
this.put("Cipher.PBEWITHSHAAND40BITRC4", "org.bouncycastle.jce.provider.JCEStreamCipher$PBEWithSHAAnd40BitRC4");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND128BITRC2-CBC", "PBEWITHSHAAND128BITRC2-CBC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND40BITRC2-CBC", "PBEWITHSHAAND40BITRC2-CBC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND128BITRC4", "PBEWITHSHAAND128BITRC4");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND40BITRC4", "PBEWITHSHAAND40BITRC4");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc.getId(), "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc.getId(), "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc.getId(), "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.getId(), "PBEWITHSHA256AND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.getId(), "PBEWITHSHA256AND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.getId(), "PBEWITHSHA256AND256BITAES-CBC-BC");
|
||||
this.put("Cipher.PBEWITHSHAAND128BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHAAND192BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHAAND256BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHA256AND128BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHA256AND192BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHA256AND256BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND128BITAES-CBC-BC", "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND192BITAES-CBC-BC", "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA1AND256BITAES-CBC-BC", "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-1AND128BITAES-CBC-BC", "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-1AND192BITAES-CBC-BC", "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-1AND256BITAES-CBC-BC", "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-256AND128BITAES-CBC-BC", "PBEWITHSHA256AND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-256AND192BITAES-CBC-BC", "PBEWITHSHA256AND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.Cipher.PBEWITHSHA-256AND256BITAES-CBC-BC", "PBEWITHSHA256AND256BITAES-CBC-BC");
|
||||
this.put("Cipher.PBEWITHMD5AND128BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHMD5AND192BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHMD5AND256BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithAESCBC");
|
||||
this.put("Cipher.PBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.JCEBlockCipher$PBEWithSHAAndTwofish");
|
||||
this.put("Cipher.OLDPBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$OldPBEWithSHAAndTwofish");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
|
||||
this.put("Alg.Alias.Cipher." + PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
|
||||
this.put("Alg.Alias.Cipher.1.2.840.113549.1.12.1.1", "PBEWITHSHAAND128BITRC4");
|
||||
this.put("Alg.Alias.Cipher.1.2.840.113549.1.12.1.2", "PBEWITHSHAAND40BITRC4");
|
||||
this.put("Alg.Alias.Cipher.1.2.840.113549.1.12.1.5", "PBEWITHSHAAND128BITRC2-CBC");
|
||||
this.put("Alg.Alias.Cipher.1.2.840.113549.1.12.1.6", "PBEWITHSHAAND40BITRC2-CBC");
|
||||
this.put("SecretKeyFactory.PBEWITHMD2ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHMD2ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD2AndRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5AndDES");
|
||||
this.put("SecretKeyFactory.PBEWITHMD5ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5AndRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA1AndDES");
|
||||
this.put("SecretKeyFactory.PBEWITHSHA1ANDRC2", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA1AndRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND3-KEYTRIPLEDES-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAndDES3Key");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND2-KEYTRIPLEDES-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAndDES2Key");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND128BITRC4", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd128BitRC4");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND40BITRC4", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd40BitRC4");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND128BITRC2-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd128BitRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND40BITRC2-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd40BitRC2");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAndTwofish");
|
||||
this.put("SecretKeyFactory.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithRIPEMD160");
|
||||
this.put("SecretKeyFactory.PBEWITHHMACSHA1", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA");
|
||||
this.put("SecretKeyFactory.PBEWITHHMACTIGER", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithTiger");
|
||||
this.put("SecretKeyFactory.PBEWITHMD5AND128BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And128BitAESCBCOpenSSL");
|
||||
this.put("SecretKeyFactory.PBEWITHMD5AND192BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And192BitAESCBCOpenSSL");
|
||||
this.put("SecretKeyFactory.PBEWITHMD5AND256BITAES-CBC-OPENSSL", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithMD5And256BitAESCBCOpenSSL");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBE", "PBE/PKCS5");
|
||||
this.put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHMD5ANDDES", "PBE/PKCS5");
|
||||
this.put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHA1ANDDES", "PBE/PKCS5");
|
||||
this.put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
|
||||
this.put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND3-KEYTRIPLEDES-CBC", "PBE/PKCS12");
|
||||
this.put("Alg.Alias.SecretKeyFactory.BROKENPBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PBE/PKCS12");
|
||||
this.put("Alg.Alias.SecretKeyFactory.OLDPBEWITHSHAANDTWOFISH-CBC", "PBE/PKCS12");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDDES-CBC", "PBEWITHMD2ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDRC2-CBC", "PBEWITHMD2ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDDES-CBC", "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDRC2-CBC", "PBEWITHMD5ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDDES-CBC", "PBEWITHSHA1ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDRC2-CBC", "PBEWITHSHA1ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.1", "PBEWITHSHAAND128BITRC4");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.2", "PBEWITHSHAAND40BITRC4");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.3", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.4", "PBEWITHSHAAND2-KEYTRIPLEDES-CBC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.5", "PBEWITHSHAAND128BITRC2-CBC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.6", "PBEWITHSHAAND40BITRC2-CBC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHHMACSHA", "PBEWITHHMACSHA1");
|
||||
this.put("Alg.Alias.SecretKeyFactory.1.3.14.3.2.26", "PBEWITHHMACSHA1");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWithSHAAnd3KeyTripleDES", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND128BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd128BitAESBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND192BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd192BitAESBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHAAND256BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHAAnd256BitAESBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHA256AND128BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA256And128BitAESBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHA256AND192BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA256And192BitAESBC");
|
||||
this.put("SecretKeyFactory.PBEWITHSHA256AND256BITAES-CBC-BC", "org.bouncycastle.jce.provider.JCESecretKeyFactory$PBEWithSHA256And256BitAESBC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND128BITAES-CBC-BC", "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND192BITAES-CBC-BC", "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND256BITAES-CBC-BC", "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND128BITAES-CBC-BC", "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND192BITAES-CBC-BC", "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND256BITAES-CBC-BC", "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND128BITAES-CBC-BC", "PBEWITHSHA256AND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND192BITAES-CBC-BC", "PBEWITHSHA256AND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND256BITAES-CBC-BC", "PBEWITHSHA256AND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc.getId(), "PBEWITHSHAAND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc.getId(), "PBEWITHSHAAND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc.getId(), "PBEWITHSHAAND256BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.getId(), "PBEWITHSHA256AND128BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.getId(), "PBEWITHSHA256AND192BITAES-CBC-BC");
|
||||
this.put("Alg.Alias.SecretKeyFactory." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.getId(), "PBEWITHSHA256AND256BITAES-CBC-BC");
|
||||
this.addMacAlgorithms();
|
||||
this.put("CertPathValidator.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathValidatorSpi");
|
||||
this.put("CertPathBuilder.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathBuilderSpi");
|
||||
this.put("CertPathValidator.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi");
|
||||
this.put("CertPathBuilder.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi");
|
||||
this.put("CertPathValidator.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi");
|
||||
this.put("CertPathBuilder.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi");
|
||||
this.put("CertStore.Collection", "org.bouncycastle.jce.provider.CertStoreCollectionSpi");
|
||||
this.put("CertStore.LDAP", "org.bouncycastle.jce.provider.X509LDAPCertStoreSpi");
|
||||
this.put("CertStore.Multi", "org.bouncycastle.jce.provider.MultiCertStoreSpi");
|
||||
this.put("Alg.Alias.CertStore.X509LDAP", "LDAP");
|
||||
}
|
||||
|
||||
private void loadAlgorithms(String par1Str, String[] par2ArrayOfStr)
|
||||
{
|
||||
for (int var3 = 0; var3 != par2ArrayOfStr.length; ++var3)
|
||||
{
|
||||
Class var4 = null;
|
||||
|
||||
try
|
||||
{
|
||||
ClassLoader var5 = this.getClass().getClassLoader();
|
||||
|
||||
if (var5 != null)
|
||||
{
|
||||
var4 = var5.loadClass(par1Str + par2ArrayOfStr[var3] + "$Mappings");
|
||||
}
|
||||
else
|
||||
{
|
||||
var4 = Class.forName(par1Str + par2ArrayOfStr[var3] + "$Mappings");
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException var7)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (var4 != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
((AlgorithmProvider)var4.newInstance()).configure(this);
|
||||
}
|
||||
catch (Exception var6)
|
||||
{
|
||||
var6.printStackTrace();
|
||||
throw new InternalError("cannot create instance of " + par1Str + par2ArrayOfStr[var3] + "$Mappings : " + var6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addMacAlgorithms()
|
||||
{
|
||||
this.put("Mac.DESWITHISO9797", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
|
||||
this.put("Alg.Alias.Mac.DESISO9797MAC", "DESWITHISO9797");
|
||||
this.put("Mac.ISO9797ALG3MAC", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3");
|
||||
this.put("Alg.Alias.Mac.ISO9797ALG3", "ISO9797ALG3MAC");
|
||||
this.put("Mac.ISO9797ALG3WITHISO7816-4PADDING", "org.bouncycastle.jce.provider.JCEMac$DES9797Alg3with7816d4");
|
||||
this.put("Alg.Alias.Mac.ISO9797ALG3MACWITHISO7816-4PADDING", "ISO9797ALG3WITHISO7816-4PADDING");
|
||||
this.put("Mac.OLDHMACSHA384", "org.bouncycastle.jce.provider.JCEMac$OldSHA384");
|
||||
this.put("Mac.OLDHMACSHA512", "org.bouncycastle.jce.provider.JCEMac$OldSHA512");
|
||||
this.put("Mac.PBEWITHHMACSHA", "org.bouncycastle.jce.provider.JCEMac$PBEWithSHA");
|
||||
this.put("Mac.PBEWITHHMACSHA1", "org.bouncycastle.jce.provider.JCEMac$PBEWithSHA");
|
||||
this.put("Mac.PBEWITHHMACRIPEMD160", "org.bouncycastle.jce.provider.JCEMac$PBEWithRIPEMD160");
|
||||
this.put("Alg.Alias.Mac.1.3.14.3.2.26", "PBEWITHHMACSHA");
|
||||
}
|
||||
|
||||
static void doSetup(BouncyCastleProvider par0BouncyCastleProvider)
|
||||
{
|
||||
par0BouncyCastleProvider.setup();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package org.bouncycastle.jce.provider;
|
||||
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
class BouncyCastleProviderAction implements PrivilegedAction
|
||||
{
|
||||
final BouncyCastleProvider theBouncyCastleProvider;
|
||||
|
||||
BouncyCastleProviderAction(BouncyCastleProvider par1BouncyCastleProvider)
|
||||
{
|
||||
this.theBouncyCastleProvider = par1BouncyCastleProvider;
|
||||
}
|
||||
|
||||
public Object run()
|
||||
{
|
||||
BouncyCastleProvider.doSetup(this.theBouncyCastleProvider);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.bouncycastle.jce.provider;
|
||||
|
||||
import java.security.Permission;
|
||||
import org.bouncycastle.jcajce.provider.config.ProviderConfiguration;
|
||||
import org.bouncycastle.jcajce.provider.config.ProviderConfigurationPermission;
|
||||
|
||||
class BouncyCastleProviderConfiguration implements ProviderConfiguration
|
||||
{
|
||||
private static Permission BC_EC_LOCAL_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, "threadLocalEcImplicitlyCa");
|
||||
private static Permission BC_EC_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, "ecImplicitlyCa");
|
||||
private static Permission BC_DH_LOCAL_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, "threadLocalDhDefaultParams");
|
||||
private static Permission BC_DH_PERMISSION = new ProviderConfigurationPermission(BouncyCastleProvider.PROVIDER_NAME, "DhDefaultParams");
|
||||
private ThreadLocal ecThreadSpec = new ThreadLocal();
|
||||
private ThreadLocal dhThreadSpec = new ThreadLocal();
|
||||
}
|
33
src/lwjgl/java/org/bouncycastle/util/Strings.java
Normal file
33
src/lwjgl/java/org/bouncycastle/util/Strings.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package org.bouncycastle.util;
|
||||
|
||||
public final class Strings
|
||||
{
|
||||
/**
|
||||
* A locale independent version of toLowerCase that returns a US ASCII lowercase String.
|
||||
*/
|
||||
public static String toLowerCase(String par0Str)
|
||||
{
|
||||
boolean var1 = false;
|
||||
char[] var2 = par0Str.toCharArray();
|
||||
|
||||
for (int var3 = 0; var3 != var2.length; ++var3)
|
||||
{
|
||||
char var4 = var2[var3];
|
||||
|
||||
if (65 <= var4 && 90 >= var4)
|
||||
{
|
||||
var1 = true;
|
||||
var2[var3] = (char)(var4 - 65 + 97);
|
||||
}
|
||||
}
|
||||
|
||||
if (var1)
|
||||
{
|
||||
return new String(var2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return par0Str;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -66,7 +66,7 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
this.dropDownOptions = EaglerProfile.concatArrays(EaglerProfile.skinNames.toArray(new String[0]), defaultOptions);
|
||||
}
|
||||
|
||||
private GuiButton button0, button1, button2;
|
||||
private GuiButton button0, button1, button2, button3;
|
||||
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
@ -81,6 +81,8 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
this.buttonList.add(button0 = new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
|
||||
this.buttonList.add(button1 = new GuiButton(2, this.width / 2 - 21, this.height / 6 + 110, 71, 20, var1.translateKey("profile.addSkin")));
|
||||
this.buttonList.add(button2 = new GuiButton(3, this.width / 2 - 21 + 71, this.height / 6 + 110, 72, 20, var1.translateKey("profile.clearSkin")));
|
||||
|
||||
this.buttonList.add(button3 = new GuiButton(4, this.width / 2 - 21 + 71, this.height / 6 + 134, 72, 20, this.mc.gameSettings.useDefaultProtocol?"Switch to Eaglercraft":"Switch to Vanilla"));
|
||||
//this.buttonList.add(new GuiButton(200, this.width / 2, this.height / 6 + 72, 150, 20, var1.translateKey("gui.done")));
|
||||
}
|
||||
|
||||
|
@ -214,6 +216,10 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
EaglerProfile.glTex.clear();
|
||||
this.dropDownOptions = defaultOptions;
|
||||
this.selectedSlot = 0;
|
||||
}else if (par1GuiButton.id == 4) {
|
||||
//toggle version mode
|
||||
this.mc.gameSettings.useDefaultProtocol=!this.mc.gameSettings.useDefaultProtocol;
|
||||
button3.displayString=this.mc.gameSettings.useDefaultProtocol?"Switch to Eaglercraft":"Switch to Vanilla";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.INetworkManager;
|
||||
import net.minecraft.src.NetHandler;
|
||||
import net.minecraft.src.Packet;
|
||||
|
||||
public class WebsocketNetworkManager implements INetworkManager {
|
||||
|
||||
private NetHandler netHandler;
|
||||
|
||||
public WebsocketNetworkManager(String uri, String eagler, NetHandler netHandler) throws IOException {
|
||||
this.netHandler = netHandler;
|
||||
if(!EaglerAdapter.startConnection(uri)) {
|
||||
throw new IOException("websocket to "+uri+" failed");
|
||||
}
|
||||
EaglerAdapter.setDebugVar("minecraftServer", uri);
|
||||
}
|
||||
|
||||
public void setNetHandler(NetHandler netHandler) {
|
||||
this.netHandler = netHandler;
|
||||
}
|
||||
|
||||
private ByteArrayOutputStream sendBuffer = new ByteArrayOutputStream();
|
||||
|
||||
public void addToSendQueue(Packet var1) {
|
||||
try {
|
||||
sendBuffer.reset();
|
||||
DataOutputStream yee = new DataOutputStream(sendBuffer);
|
||||
Packet.writePacket(var1, yee);
|
||||
EaglerAdapter.writePacket(sendBuffer.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeThreads() {
|
||||
}
|
||||
|
||||
private static class ByteBufferDirectInputStream extends InputStream {
|
||||
private ByteBuffer buf;
|
||||
private ByteBufferDirectInputStream(ByteBuffer b) {
|
||||
this.buf = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return buf.remaining() > 0 ? ((int)buf.get() & 0xFF) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return buf.remaining();
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer oldChunkBuffer = null;
|
||||
private LinkedList<ByteBuffer> readChunks = new LinkedList();
|
||||
|
||||
public void processReadPackets() {
|
||||
readChunks.clear();
|
||||
|
||||
if(oldChunkBuffer != null) {
|
||||
readChunks.add(oldChunkBuffer);
|
||||
}
|
||||
|
||||
byte[] packet;
|
||||
while((packet = EaglerAdapter.readPacket()) != null) {
|
||||
readChunks.add(ByteBuffer.wrap(packet));
|
||||
}
|
||||
if(!readChunks.isEmpty()) {
|
||||
|
||||
int cap = 0;
|
||||
for(ByteBuffer b : readChunks) {
|
||||
cap += b.limit();
|
||||
}
|
||||
|
||||
ByteBuffer stream = ByteBuffer.allocate(cap);
|
||||
for(ByteBuffer b : readChunks) {
|
||||
stream.put(b);
|
||||
}
|
||||
stream.flip();
|
||||
|
||||
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream));
|
||||
while(stream.hasRemaining()) {
|
||||
stream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
//System.out.println(pkt.toString());
|
||||
pkt.processPacket(this.netHandler);
|
||||
} catch (EOFException e) {
|
||||
stream.reset();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(stream.hasRemaining()) {
|
||||
oldChunkBuffer = stream.slice();
|
||||
}else {
|
||||
oldChunkBuffer = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void serverShutdown() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
public int packetSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void networkShutdown(String var1, Object... var2) {
|
||||
serverShutdown();
|
||||
}
|
||||
|
||||
public void closeConnections() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,9 @@ import net.lax1dude.eaglercraft.LocalStorageManager;
|
|||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class GameSettings {
|
||||
public static boolean useDefaultProtocol = false;
|
||||
|
||||
|
||||
private static final String[] RENDER_DISTANCES = new String[] { "options.renderDistance.far", "options.renderDistance.normal", "options.renderDistance.short", "options.renderDistance.tiny" };
|
||||
private static final String[] DIFFICULTIES = new String[] { "options.difficulty.peaceful", "options.difficulty.easy", "options.difficulty.normal", "options.difficulty.hard" };
|
||||
|
||||
|
|
|
@ -69,8 +69,12 @@ public class GuiConnecting extends GuiScreen {
|
|||
}
|
||||
|
||||
this.clientHandler = new NetClientHandler(this.mc, uri, 0);
|
||||
if(this.mc.gameSettings.useDefaultProtocol) {
|
||||
this.clientHandler.addToSendQueue(new Packet2ClientProtocol(61, EaglerProfile.username, uria, port));
|
||||
}else{
|
||||
this.clientHandler.addToSendQueue(new Packet2ClientProtocol(69, EaglerProfile.username, uria, port));
|
||||
this.clientHandler.addToSendQueue(new Packet250CustomPayload("EAG|MySkin", EaglerProfile.getSkinPacket()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
this.mc.displayGuiScreen(new GuiDisconnected(this.field_98098_c, "connect.failed", "disconnect.genericReason", "could not connect to "+uri, e.toString()));
|
||||
|
|
|
@ -76,7 +76,7 @@ public class GuiMainMenu extends GuiScreen {
|
|||
* RunnableTitleScreen(this), "1.6 Update Check Thread")).start(); }
|
||||
*/
|
||||
|
||||
this.field_92025_p = EaglerAdapter._wisWebGL() ? ("eaglercraft javascript runtime") : ("eaglercraft desktop runtime");
|
||||
this.field_92025_p = EaglerAdapter._wisWebGL() ? ("ayuncraft javascript runtime") : ("ayuncraft desktop runtime");
|
||||
this.start = System.currentTimeMillis() + System.currentTimeMillis() % 10000l;
|
||||
this.ackLines = new ArrayList();
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class GuiMainMenu extends GuiScreen {
|
|||
Calendar var1 = Calendar.getInstance();
|
||||
var1.setTime(new Date());
|
||||
|
||||
this.splashText = "darviglet!";
|
||||
this.splashText = "fard!";
|
||||
|
||||
StringTranslate var2 = StringTranslate.getInstance();
|
||||
int var4 = this.height / 4 + 48;
|
||||
|
@ -464,7 +464,7 @@ public class GuiMainMenu extends GuiScreen {
|
|||
// 16777215);
|
||||
}
|
||||
|
||||
var10 = "eaglercraft readme.txt";
|
||||
var10 = "ayuncraft readme.txt";
|
||||
int w = this.fontRenderer.getStringWidth(var10) * 3 / 4;
|
||||
if(!showAck && par1 >= (this.width - w - 4) && par1 <= this.width && par2 >= 0 && par2 <= 9) {
|
||||
drawRect((this.width - w - 4), 0, this.width, 9, 0x55000099);
|
||||
|
|
|
@ -3,19 +3,16 @@ package net.minecraft.src;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
import net.lax1dude.eaglercraft.DefaultSkinRenderer;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.WebsocketNetworkManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class NetClientHandler extends NetHandler {
|
||||
|
||||
/** True if kicked or disconnected from the server. */
|
||||
private boolean disconnected = false;
|
||||
|
||||
|
@ -87,8 +84,8 @@ public class NetClientHandler extends NetHandler {
|
|||
}
|
||||
|
||||
public void handleServerAuthData(Packet253ServerAuthData par1Packet253ServerAuthData) {
|
||||
|
||||
this.addToSendQueue(new Packet252SharedKey());
|
||||
//String var2 = par1Packet253ServerAuthData.getServerId().trim();
|
||||
this.addToSendQueue(new Packet252SharedKey(CryptManager.createNewSharedKey(), par1Packet253ServerAuthData.getPublicKey(), par1Packet253ServerAuthData.getVerifyToken()));
|
||||
}
|
||||
|
||||
public void handleSharedKey(Packet252SharedKey par1Packet252SharedKey) {
|
||||
|
@ -1113,7 +1110,7 @@ public class NetClientHandler extends NetHandler {
|
|||
} catch (IOException var7) {
|
||||
var7.printStackTrace();
|
||||
}
|
||||
}else if("EAG|UserSkin".equals(par1Packet250CustomPayload.channel)) {
|
||||
}else if(!this.mc.gameSettings.useDefaultProtocol&&"EAG|UserSkin".equals(par1Packet250CustomPayload.channel)) {
|
||||
DefaultSkinRenderer.skinResponse(par1Packet250CustomPayload.data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -38,10 +40,14 @@ public class Packet250CustomPayload extends Packet {
|
|||
this.length = par1DataInputStream.readShort();
|
||||
|
||||
if (this.length > 0 && this.length < 32767) {
|
||||
if(Minecraft.getMinecraft().gameSettings.useDefaultProtocol){
|
||||
par1DataInputStream.skipBytes(this.length);
|
||||
}else {
|
||||
this.data = new byte[this.length];
|
||||
par1DataInputStream.readFully(this.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Packet252SharedKey extends Packet {
|
||||
|
||||
public Packet252SharedKey() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException {
|
||||
readBytesFromStream(par1DataInputStream);
|
||||
readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException {
|
||||
writeByteArray(par1DataOutputStream, new byte[162]);
|
||||
writeByteArray(par1DataOutputStream, new byte[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler) {
|
||||
par1NetHandler.handleSharedKey(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize() {
|
||||
return 2 + 162 + 2 + 4;
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Packet253ServerAuthData extends Packet {
|
||||
private String serverId;
|
||||
private byte[] verifyToken = new byte[0];
|
||||
|
||||
public Packet253ServerAuthData() {
|
||||
}
|
||||
|
||||
public Packet253ServerAuthData(String par1Str, byte[] par3ArrayOfByte) {
|
||||
this.serverId = par1Str;
|
||||
this.verifyToken = par3ArrayOfByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException {
|
||||
this.serverId = readString(par1DataInputStream, 20);
|
||||
readBytesFromStream(par1DataInputStream);
|
||||
this.verifyToken = readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException {
|
||||
writeString(this.serverId, par1DataOutputStream);
|
||||
writeByteArray(par1DataOutputStream, new byte[0]);
|
||||
writeByteArray(par1DataOutputStream, this.verifyToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler) {
|
||||
par1NetHandler.handleServerAuthData(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize() {
|
||||
return 2 + this.serverId.length() * 2 + 2 + 0 + 2 + this.verifyToken.length;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
public byte[] getVerifyToken() {
|
||||
return this.verifyToken;
|
||||
}
|
||||
}
|
|
@ -324,7 +324,7 @@ public class SoundManager {
|
|||
|
||||
public void playTheTitleMusic() {
|
||||
if(titleMusic == -1 || !EaglerAdapter.isPlaying(titleMusic)) {
|
||||
titleMusic = EaglerAdapter.beginPlaybackStatic("/sounds/gta.mp3", 1.0f, 1.0f);
|
||||
titleMusic = EaglerAdapter.beginPlaybackStatic("/sounds/gta.mp3", this.options.musicVolume, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
123
src/teavm/java/me/ayunami2000/ayuncraft/CryptManager.java
Normal file
123
src/teavm/java/me/ayunami2000/ayuncraft/CryptManager.java
Normal file
|
@ -0,0 +1,123 @@
|
|||
package me.ayunami2000.ayuncraft;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import me.ayunami2000.ayuncraft.java.security.Key;
|
||||
|
||||
import net.lax1dude.eaglercraft.Base64;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.engines.AESFastEngine;
|
||||
import org.bouncycastle.crypto.io.CipherInputStream;
|
||||
import org.bouncycastle.crypto.io.CipherOutputStream;
|
||||
import org.bouncycastle.crypto.modes.CFBBlockCipher;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.SecretKey;
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.spec.SecretKeySpec;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
|
||||
public class CryptManager
|
||||
{
|
||||
//i hate security !!
|
||||
/**
|
||||
* Generate a new shared secret AES key from a static preset key
|
||||
*/
|
||||
private static final byte[] baseSharedKey = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||
public static SecretKey createNewSharedKey(){
|
||||
return new SecretKeySpec(baseSharedKey,"AES");
|
||||
}
|
||||
|
||||
@JSBody(params = {"base64enc"}, script =
|
||||
"var xd=window.ASN1.parse(window.PEM.parseBlock(base64enc).der);" +
|
||||
"xd=xd.children.find(e=>{return e.type==3;});" +
|
||||
"xd=xd.children.find(e=>{return e.type==48;});" +
|
||||
"return [xd.children[0].value,xd.children[1].value];")
|
||||
private static native Uint8Array[] x509decode(String base64enc);
|
||||
|
||||
/**
|
||||
* Create a new PublicKey from encoded X.509 data
|
||||
*/
|
||||
public static PubKey decodePublicKey(byte[] par0ArrayOfByte)
|
||||
{
|
||||
Uint8Array[] resarr=x509decode(Base64.encodeBase64String(par0ArrayOfByte));
|
||||
PubKey results = new PubKey(par0ArrayOfByte,new BigInteger(uInt8toByteArr(resarr[0])),new BigInteger(uInt8toByteArr(resarr[1])));
|
||||
return results;
|
||||
}
|
||||
|
||||
private static byte[] uInt8toByteArr(Uint8Array a){
|
||||
byte[] b = new byte[a.getByteLength()];
|
||||
for(int i = 0; i < b.length; ++i) {
|
||||
b[i] = (byte) (a.get(i) & 0xFF);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt shared secret AES key using RSA private key
|
||||
*/
|
||||
public static SecretKey decryptSharedKey(PubKey par0PrivateKey, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return new SecretKeySpec(decryptData(par0PrivateKey, par1ArrayOfByte), "AES");
|
||||
}
|
||||
|
||||
@JSBody(params = {"pubkey", "mod", "indata"}, script =
|
||||
"var rsa=new RSAKey();" +
|
||||
"rsa.setPublic(b64tohex(mod),b64tohex(pubkey));" +
|
||||
"return hex2b64(rsa.encrypt(b64tohex(indata)));")
|
||||
private static native String encryptDataNative(String pubkey, String mod, String indata);
|
||||
|
||||
@JSBody(params = {"privkey", "mod", "indata"}, script =
|
||||
"var rsa=new RSAKey();" +
|
||||
"rsa.setPrivate(b64tohex(mod),b64tohex(privkey));" +
|
||||
"return hex2b64(rsa.decrypt(b64tohex(indata)));")
|
||||
private static native String decryptDataNative(String pubkey, String mod, String indata);
|
||||
|
||||
/**
|
||||
* Encrypt byte[] data with RSA public key
|
||||
*/
|
||||
public static byte[] encryptData(PubKey par0Key, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return Base64.decodeBase64(encryptDataNative(Base64.encodeBase64String(par0Key.getPriExp().toByteArray()),Base64.encodeBase64String(par0Key.getModulus().toByteArray()),Base64.encodeBase64String(par1ArrayOfByte)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt byte[] data with RSA private key
|
||||
*/
|
||||
public static byte[] decryptData(PubKey par0Key, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return Base64.decodeBase64(decryptDataNative(Base64.encodeBase64String(par0Key.getPriExp().toByteArray()),Base64.encodeBase64String(par0Key.getModulus().toByteArray()),Base64.encodeBase64String(par1ArrayOfByte)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new BufferedBlockCipher instance
|
||||
*/
|
||||
public static BufferedBlockCipher createBufferedBlockCipher(boolean par0, Key par1Key)
|
||||
{
|
||||
BufferedBlockCipher var2 = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
|
||||
var2.init(par0, new ParametersWithIV(new KeyParameter(par1Key.getEncoded()), par1Key.getEncoded(), 0, 16));
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static OutputStream encryptOuputStream(SecretKey par0SecretKey, OutputStream par1OutputStream)
|
||||
{
|
||||
return new CipherOutputStream(par1OutputStream, createBufferedBlockCipher(true, par0SecretKey));
|
||||
}
|
||||
|
||||
public static InputStream decryptInputStream(SecretKey par0SecretKey, InputStream par1InputStream)
|
||||
{
|
||||
return new CipherInputStream(par1InputStream, createBufferedBlockCipher(false, par0SecretKey));
|
||||
}
|
||||
|
||||
public static OutputStream encryptOuputStream(BufferedBlockCipher bufferedBlockCipher, OutputStream par1OutputStream)
|
||||
{
|
||||
return new CipherOutputStream(par1OutputStream, bufferedBlockCipher);
|
||||
}
|
||||
|
||||
public static InputStream decryptInputStream(BufferedBlockCipher bufferedBlockCipher, InputStream par1InputStream)
|
||||
{
|
||||
return new CipherInputStream(par1InputStream, bufferedBlockCipher);
|
||||
}
|
||||
}
|
27
src/teavm/java/me/ayunami2000/ayuncraft/PubKey.java
Normal file
27
src/teavm/java/me/ayunami2000/ayuncraft/PubKey.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package me.ayunami2000.ayuncraft;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class PubKey {
|
||||
private static byte[] encoded=null;
|
||||
private static BigInteger modulus=null;
|
||||
private static BigInteger priexp=null;
|
||||
|
||||
public PubKey(byte[] e, BigInteger m, BigInteger p){
|
||||
encoded=e;
|
||||
modulus=m;
|
||||
priexp=p;
|
||||
}
|
||||
|
||||
public byte[] getEncoded(){
|
||||
return encoded;
|
||||
}
|
||||
|
||||
public BigInteger getModulus(){
|
||||
return modulus;
|
||||
}
|
||||
|
||||
public BigInteger getPriExp(){
|
||||
return priexp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package me.ayunami2000.ayuncraft.java.security;
|
||||
|
||||
public interface Key {
|
||||
public String getAlgorithm();
|
||||
|
||||
public String getFormat();
|
||||
|
||||
public byte[] getEncoded();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package me.ayunami2000.ayuncraft.java.security.spec;
|
||||
|
||||
public interface KeySpec { }
|
|
@ -0,0 +1,6 @@
|
|||
package me.ayunami2000.ayuncraft.javax.crypto;
|
||||
|
||||
import me.ayunami2000.ayuncraft.java.security.Key;
|
||||
|
||||
public interface SecretKey extends Key {
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package me.ayunami2000.ayuncraft.javax.crypto.spec;
|
||||
|
||||
import me.ayunami2000.ayuncraft.java.security.spec.KeySpec;
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.SecretKey;
|
||||
|
||||
public class SecretKeySpec implements KeySpec, SecretKey {
|
||||
private String algorithm;
|
||||
private byte[] key;
|
||||
|
||||
public String getAlgorithm() {
|
||||
return this.algorithm;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return "RAW";
|
||||
}
|
||||
|
||||
public byte[] getEncoded() {
|
||||
byte[] tmp = new byte[this.key.length];
|
||||
System.arraycopy(this.key, 0, tmp, 0, tmp.length);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int code = this.algorithm.toUpperCase().hashCode();
|
||||
|
||||
for(int i = 0; i != this.key.length; ++i) {
|
||||
code ^= this.key[i] << 8 * (i % 4);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof SecretKeySpec) {
|
||||
SecretKeySpec spec = (SecretKeySpec)obj;
|
||||
if (!this.algorithm.equalsIgnoreCase(spec.algorithm)) {
|
||||
return false;
|
||||
} else if (this.key.length != spec.key.length) {
|
||||
return false;
|
||||
} else {
|
||||
for(int i = 0; i != this.key.length; ++i) {
|
||||
if (this.key[i] != spec.key[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SecretKeySpec(byte[] key, String algorithm) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("null key passed");
|
||||
} else if (algorithm == null) {
|
||||
throw new IllegalArgumentException("null algorithm passed");
|
||||
} else {
|
||||
this.key = new byte[key.length];
|
||||
System.arraycopy(key, 0, this.key, 0, key.length);
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
}
|
||||
|
||||
public SecretKeySpec(byte[] key, int offset, int len, String algorithm) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("Null key passed");
|
||||
} else if (key.length - offset < len) {
|
||||
throw new IllegalArgumentException("Bad offset/len");
|
||||
} else if (algorithm == null) {
|
||||
throw new IllegalArgumentException("Null algorithm string passed");
|
||||
} else {
|
||||
this.key = new byte[len];
|
||||
System.arraycopy(key, offset, this.key, 0, len);
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,263 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import me.ayunami2000.ayuncraft.java.security.Key;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.*;
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.SecretKey;
|
||||
|
||||
public class WebsocketNetworkManager implements INetworkManager {
|
||||
private boolean isInputBeingDecrypted;
|
||||
private boolean isOutputEncrypted;
|
||||
private SecretKey sharedKeyForEncryption;
|
||||
|
||||
private final boolean logpackets=false;
|
||||
|
||||
private BufferedBlockCipher inputBufferedBlockCipher=null;
|
||||
private BufferedBlockCipher outputBufferedBlockCipher=null;
|
||||
|
||||
private NetHandler netHandler;
|
||||
|
||||
public WebsocketNetworkManager(String uri, String eagler, NetHandler netHandler) throws IOException {
|
||||
this.netHandler = netHandler;
|
||||
this.sharedKeyForEncryption = null;
|
||||
this.isInputBeingDecrypted = false;
|
||||
this.isOutputEncrypted = false;
|
||||
if(!EaglerAdapter.startConnection(uri)) {
|
||||
throw new IOException("websocket to "+uri+" failed");
|
||||
}
|
||||
EaglerAdapter.setDebugVar("minecraftServer", uri);
|
||||
}
|
||||
|
||||
public void setNetHandler(NetHandler netHandler) {
|
||||
this.netHandler = netHandler;
|
||||
}
|
||||
|
||||
private ByteArrayOutputStream sendBuffer = new ByteArrayOutputStream();
|
||||
|
||||
public void addToSendQueue(Packet var1) {
|
||||
try {
|
||||
sendBuffer.reset();
|
||||
|
||||
DataOutputStream yee;
|
||||
if(this.isOutputEncrypted&&!(var1 instanceof Packet252SharedKey)){
|
||||
yee = this.encryptOuputStream();
|
||||
}else{
|
||||
yee = new DataOutputStream(sendBuffer);
|
||||
}
|
||||
|
||||
if (Minecraft.getMinecraft().gameSettings.useDefaultProtocol && var1 instanceof Packet252SharedKey && !this.isOutputEncrypted)
|
||||
{
|
||||
this.sharedKeyForEncryption = ((Packet252SharedKey)var1).getSharedKey();
|
||||
this.isOutputEncrypted=true;
|
||||
//yee=this.encryptOuputStream(yee);
|
||||
}
|
||||
Packet.writePacket(var1, yee);
|
||||
if(logpackets)System.out.println("SENDING: "+var1);
|
||||
yee.flush();
|
||||
EaglerAdapter.writePacket(sendBuffer.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeThreads() {
|
||||
}
|
||||
|
||||
private static class ByteBufferDirectInputStream extends InputStream {
|
||||
private ByteBuffer buf;
|
||||
private ByteBufferDirectInputStream(ByteBuffer b) {
|
||||
this.buf = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return buf.remaining() > 0 ? ((int)buf.get() & 0xFF) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return buf.remaining();
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer oldChunkBuffer = null;
|
||||
private LinkedList<ByteBuffer> readChunks = new LinkedList();
|
||||
|
||||
private ByteBuffer oldDecryptedChunkBuffer = null;
|
||||
private LinkedList<ByteBuffer> decryptedReadChunks = new LinkedList();
|
||||
|
||||
public void processReadPackets() {
|
||||
readChunks.clear();
|
||||
|
||||
if(oldChunkBuffer != null) {
|
||||
readChunks.add(oldChunkBuffer);
|
||||
}
|
||||
|
||||
byte[] packet;
|
||||
while((packet = EaglerAdapter.readPacket()) != null) {
|
||||
readChunks.add(ByteBuffer.wrap(packet));
|
||||
}
|
||||
if(!readChunks.isEmpty()) {
|
||||
|
||||
int cap = 0;
|
||||
for(ByteBuffer b : readChunks) {
|
||||
cap += b.limit();
|
||||
}
|
||||
|
||||
ByteBuffer stream = ByteBuffer.allocate(cap);
|
||||
for(ByteBuffer b : readChunks) {
|
||||
stream.put(b);
|
||||
}
|
||||
stream.flip();
|
||||
|
||||
if(this.isInputBeingDecrypted){
|
||||
decryptedReadChunks.clear();
|
||||
|
||||
if (oldDecryptedChunkBuffer != null) {
|
||||
decryptedReadChunks.add(oldDecryptedChunkBuffer);
|
||||
oldDecryptedChunkBuffer = null;
|
||||
}
|
||||
|
||||
byte[] block = new byte[/*2048*/32];
|
||||
byte[] decryp = new byte[this.inputBufferedBlockCipher.getOutputSize(/*2048*/32)];
|
||||
while (stream.remaining() >= /*2048*/32) {
|
||||
stream.get(block);
|
||||
int i = this.inputBufferedBlockCipher.processByte(block, 0, /*2048*/32, decryp, 0);
|
||||
ByteBuffer chunk = ByteBuffer.allocate(i);
|
||||
chunk.put(decryp, 0, i);
|
||||
chunk.flip();
|
||||
decryptedReadChunks.add(chunk);
|
||||
}
|
||||
|
||||
oldChunkBuffer = stream.remaining() > 0 ? stream.slice() : null;
|
||||
|
||||
int cap2 = 0;
|
||||
for (ByteBuffer b : decryptedReadChunks) {
|
||||
cap2 += b.limit();
|
||||
}
|
||||
|
||||
ByteBuffer decStream = ByteBuffer.allocate(cap2);
|
||||
for (ByteBuffer b : decryptedReadChunks) {
|
||||
decStream.put(b);
|
||||
}
|
||||
decStream.flip();
|
||||
|
||||
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(decStream));
|
||||
while (decStream.hasRemaining()) {
|
||||
decStream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
if(logpackets)System.out.println("RECEIVING: " + pkt);
|
||||
pkt.processPacket(this.netHandler);
|
||||
} catch (EOFException e) {
|
||||
decStream.reset();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (decStream.hasRemaining()) {
|
||||
oldDecryptedChunkBuffer = decStream.slice();
|
||||
} else {
|
||||
oldDecryptedChunkBuffer = null;
|
||||
}
|
||||
}else {
|
||||
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream));
|
||||
while (stream.hasRemaining()) {
|
||||
stream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
boolean change=false;
|
||||
if (pkt != null) {
|
||||
if (Minecraft.getMinecraft().gameSettings.useDefaultProtocol && pkt instanceof Packet252SharedKey && !this.isInputBeingDecrypted) {
|
||||
packetStream = this.decryptInputStream(new ByteBufferDirectInputStream(stream));
|
||||
change=true;
|
||||
}
|
||||
if(logpackets)System.out.println("RECEIVING: " + pkt);
|
||||
pkt.processPacket(this.netHandler);
|
||||
if(change){
|
||||
processReadPackets();
|
||||
return;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
stream.reset();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (stream.hasRemaining()) {
|
||||
oldChunkBuffer = stream.slice();
|
||||
} else {
|
||||
oldChunkBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void serverShutdown() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
private DataInputStream decryptInputStream(ByteBufferDirectInputStream var1) throws IOException
|
||||
{
|
||||
this.isInputBeingDecrypted = true;
|
||||
if(this.inputBufferedBlockCipher==null){
|
||||
this.inputBufferedBlockCipher = CryptManager.createBufferedBlockCipher(false, (Key) this.sharedKeyForEncryption);
|
||||
}
|
||||
return new DataInputStream(CryptManager.decryptInputStream(this.inputBufferedBlockCipher, var1));
|
||||
}
|
||||
|
||||
/**
|
||||
* flushes the stream and replaces it with an encryptedOutputStream
|
||||
*/
|
||||
private DataOutputStream encryptOuputStream(DataOutputStream var0) throws IOException
|
||||
{
|
||||
var0.flush();
|
||||
this.isOutputEncrypted = true;
|
||||
BufferedOutputStream var1 = new BufferedOutputStream(CryptManager.encryptOuputStream(this.sharedKeyForEncryption, var0), 5120);
|
||||
return new DataOutputStream(var1);
|
||||
}
|
||||
private DataOutputStream encryptOuputStream() throws IOException
|
||||
{
|
||||
if(this.outputBufferedBlockCipher==null){
|
||||
this.outputBufferedBlockCipher = CryptManager.createBufferedBlockCipher(true, (Key) this.sharedKeyForEncryption);
|
||||
}
|
||||
BufferedOutputStream var1 = new BufferedOutputStream(CryptManager.encryptOuputStream(this.outputBufferedBlockCipher, sendBuffer), 5120);
|
||||
return new DataOutputStream(var1);
|
||||
}
|
||||
|
||||
public int packetSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void networkShutdown(String var1, Object... var2) {
|
||||
serverShutdown();
|
||||
}
|
||||
|
||||
public void closeConnections() {
|
||||
if(EaglerAdapter.connectionOpen()) {
|
||||
EaglerAdapter.endConnection();
|
||||
EaglerAdapter.setDebugVar("minecraftServer", "null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1120,7 +1120,7 @@ public class EaglerAdapterImpl2 {
|
|||
float var17 = 1.0F;
|
||||
float var18 = 0.0F;
|
||||
AudioListener l = audioctx.getListener();
|
||||
l.setPosition(x, y, z);
|
||||
if(!(Float.isInfinite(x) || Float.isInfinite(y) || Float.isInfinite(z)))l.setPosition(x, y, z);
|
||||
l.setOrientation(var13, var14, var15, var16, var17, var18);
|
||||
//l.setVelocity(vx, vy, vz);
|
||||
}
|
||||
|
@ -1187,7 +1187,7 @@ public class EaglerAdapterImpl2 {
|
|||
s.setBuffer(b);
|
||||
s.getPlaybackRate().setValue(pitch);
|
||||
PannerNode p = audioctx.createPanner();
|
||||
p.setPosition(x, y, z);
|
||||
if(!(Float.isInfinite(x) || Float.isInfinite(y) || Float.isInfinite(z)))p.setPosition(x, y, z);
|
||||
p.setMaxDistance(volume * 16f + 0.1f);
|
||||
p.setRolloffFactor(1f);
|
||||
//p.setVelocity(0f, 0f, 0f);
|
||||
|
@ -1253,7 +1253,7 @@ public class EaglerAdapterImpl2 {
|
|||
}
|
||||
public static final void moveSound(int id, float x, float y, float z, float vx, float vy, float vz) {
|
||||
AudioBufferSourceNodeX b = activeSoundEffects.get(id);
|
||||
if(b != null && b.panner != null) {
|
||||
if(b != null && b.panner != null && !(Float.isInfinite(x) || Float.isInfinite(y) || Float.isInfinite(z))) {
|
||||
b.panner.setPosition(x, y, z);
|
||||
//b.panner.setVelocity(vx, vy, vz);
|
||||
}
|
||||
|
|
88
src/teavm/java/net/minecraft/src/Packet252SharedKey.java
Normal file
88
src/teavm/java/net/minecraft/src/Packet252SharedKey.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import me.ayunami2000.ayuncraft.PubKey;
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.SecretKey;
|
||||
|
||||
public class Packet252SharedKey extends Packet
|
||||
{
|
||||
private byte[] sharedSecret = new byte[0];
|
||||
private byte[] verifyToken = new byte[0];
|
||||
|
||||
/**
|
||||
* Secret AES key decrypted from sharedSecret via the server's private RSA key
|
||||
*/
|
||||
private SecretKey sharedKey;
|
||||
|
||||
public Packet252SharedKey() {}
|
||||
|
||||
public Packet252SharedKey(SecretKey par1SecretKey, PubKey par2PublicKey, byte[] par3ArrayOfByte)
|
||||
{
|
||||
this.sharedKey = par1SecretKey;
|
||||
this.sharedSecret = CryptManager.encryptData(par2PublicKey, par1SecretKey.getEncoded());
|
||||
this.verifyToken = CryptManager.encryptData(par2PublicKey, par3ArrayOfByte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException
|
||||
{
|
||||
this.sharedSecret = readBytesFromStream(par1DataInputStream);
|
||||
this.verifyToken = readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
writeByteArray(par1DataOutputStream, this.sharedSecret);
|
||||
writeByteArray(par1DataOutputStream, this.verifyToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler)
|
||||
{
|
||||
par1NetHandler.handleSharedKey(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize()
|
||||
{
|
||||
return 2 + this.sharedSecret.length + 2 + this.verifyToken.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return secretKey, decrypting it from the sharedSecret byte array if needed
|
||||
*/
|
||||
public SecretKey getSharedKey(PubKey par1PrivateKey)
|
||||
{
|
||||
return par1PrivateKey == null ? this.sharedKey : (this.sharedKey = CryptManager.decryptSharedKey(par1PrivateKey, this.sharedSecret));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the secret AES sharedKey (used by client only)
|
||||
*/
|
||||
public SecretKey getSharedKey()
|
||||
{
|
||||
return this.getSharedKey(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return verifyToken
|
||||
*/
|
||||
public byte[] getVerifyToken(PubKey par1PrivateKey)
|
||||
{
|
||||
return par1PrivateKey == null ? this.verifyToken : CryptManager.decryptData(par1PrivateKey, this.verifyToken);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import me.ayunami2000.ayuncraft.PubKey;
|
||||
|
||||
public class Packet253ServerAuthData extends Packet
|
||||
{
|
||||
private String serverId;
|
||||
private PubKey publicKey;
|
||||
private byte[] verifyToken = new byte[0];
|
||||
|
||||
public Packet253ServerAuthData() {}
|
||||
|
||||
public Packet253ServerAuthData(String par1Str, PubKey par2PublicKey, byte[] par3ArrayOfByte)
|
||||
{
|
||||
this.serverId = par1Str;
|
||||
this.publicKey = par2PublicKey;
|
||||
this.verifyToken = par3ArrayOfByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Reads the raw packet data from the data stream.
|
||||
*/
|
||||
public void readPacketData(DataInputStream par1DataInputStream) throws IOException
|
||||
{
|
||||
this.serverId = readString(par1DataInputStream, 20);
|
||||
this.publicKey = CryptManager.decodePublicKey(readBytesFromStream(par1DataInputStream));
|
||||
this.verifyToken = readBytesFromStream(par1DataInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Writes the raw packet data to the data stream.
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
writeString(this.serverId, par1DataOutputStream);
|
||||
writeByteArray(par1DataOutputStream, this.publicKey.getEncoded());
|
||||
writeByteArray(par1DataOutputStream, this.verifyToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes this Packet on to the NetHandler for processing.
|
||||
*/
|
||||
public void processPacket(NetHandler par1NetHandler)
|
||||
{
|
||||
par1NetHandler.handleServerAuthData(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract. Return the size of the packet (not counting the header).
|
||||
*/
|
||||
public int getPacketSize()
|
||||
{
|
||||
return 2 + this.serverId.length() * 2 + 2 + this.publicKey.getEncoded().length + 2 + this.verifyToken.length;
|
||||
}
|
||||
|
||||
public String getServerId()
|
||||
{
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
public PubKey getPublicKey()
|
||||
{
|
||||
return this.publicKey;
|
||||
}
|
||||
|
||||
public byte[] getVerifyToken()
|
||||
{
|
||||
return this.verifyToken;
|
||||
}
|
||||
}
|
20
src/teavm/java/org/bouncycastle/crypto/BlockCipher.java
Normal file
20
src/teavm/java/org/bouncycastle/crypto/BlockCipher.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface BlockCipher
|
||||
{
|
||||
void init(boolean var1, CipherParameters var2) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
String getAlgorithmName();
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
int getBlockSize();
|
||||
|
||||
int processBlock(byte[] var1, int var2, byte[] var3, int var4) throws DataLengthException, IllegalStateException;
|
||||
|
||||
void reset();
|
||||
}
|
161
src/teavm/java/org/bouncycastle/crypto/BufferedBlockCipher.java
Normal file
161
src/teavm/java/org/bouncycastle/crypto/BufferedBlockCipher.java
Normal file
|
@ -0,0 +1,161 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class BufferedBlockCipher
|
||||
{
|
||||
protected byte[] buf;
|
||||
protected int bufOff;
|
||||
protected boolean forEncryption;
|
||||
protected BlockCipher cipher;
|
||||
protected boolean partialBlockOkay;
|
||||
protected boolean pgpCFB;
|
||||
|
||||
protected BufferedBlockCipher() {}
|
||||
|
||||
public BufferedBlockCipher(BlockCipher par1BlockCipher)
|
||||
{
|
||||
this.cipher = par1BlockCipher;
|
||||
this.buf = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.bufOff = 0;
|
||||
String var2 = par1BlockCipher.getAlgorithmName();
|
||||
int var3 = var2.indexOf(47) + 1;
|
||||
this.pgpCFB = var3 > 0 && var2.startsWith("PGP", var3);
|
||||
|
||||
if (this.pgpCFB)
|
||||
{
|
||||
this.partialBlockOkay = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.partialBlockOkay = var3 > 0 && (var2.startsWith("CFB", var3) || var2.startsWith("OFB", var3) || var2.startsWith("OpenPGP", var3) || var2.startsWith("SIC", var3) || var2.startsWith("GCTR", var3));
|
||||
}
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
this.forEncryption = par1;
|
||||
this.reset();
|
||||
this.cipher.init(par1, par2CipherParameters);
|
||||
}
|
||||
|
||||
public int getBlockSize()
|
||||
{
|
||||
return this.cipher.getBlockSize();
|
||||
}
|
||||
|
||||
public int getUpdateOutputSize(int par1)
|
||||
{
|
||||
int var2 = par1 + this.bufOff;
|
||||
int var3;
|
||||
|
||||
if (this.pgpCFB)
|
||||
{
|
||||
var3 = var2 % this.buf.length - (this.cipher.getBlockSize() + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var3 = var2 % this.buf.length;
|
||||
}
|
||||
|
||||
return var2 - var3;
|
||||
}
|
||||
|
||||
public int getOutputSize(int par1)
|
||||
{
|
||||
return par1 + this.bufOff;
|
||||
}
|
||||
|
||||
public int processByte(byte[] par1ArrayOfByte, int par2, int par3, byte[] par4ArrayOfByte, int par5) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par3 < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Can\'t have a negative input length!");
|
||||
}
|
||||
else
|
||||
{
|
||||
int var6 = this.getBlockSize();
|
||||
int var7 = this.getUpdateOutputSize(par3);
|
||||
|
||||
if (var7 > 0 && par5 + var7 > par4ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
int var8 = 0;
|
||||
int var9 = this.buf.length - this.bufOff;
|
||||
|
||||
if (par3 > var9)
|
||||
{
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.buf, this.bufOff, var9);
|
||||
var8 += this.cipher.processBlock(this.buf, 0, par4ArrayOfByte, par5);
|
||||
this.bufOff = 0;
|
||||
par3 -= var9;
|
||||
|
||||
for (par2 += var9; par3 > this.buf.length; par2 += var6)
|
||||
{
|
||||
var8 += this.cipher.processBlock(par1ArrayOfByte, par2, par4ArrayOfByte, par5 + var8);
|
||||
par3 -= var6;
|
||||
}
|
||||
}
|
||||
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.buf, this.bufOff, par3);
|
||||
this.bufOff += par3;
|
||||
|
||||
if (this.bufOff == this.buf.length)
|
||||
{
|
||||
var8 += this.cipher.processBlock(this.buf, 0, par4ArrayOfByte, par5 + var8);
|
||||
this.bufOff = 0;
|
||||
}
|
||||
|
||||
return var8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int doFinal(byte[] par1ArrayOfByte, int par2) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
int var4;
|
||||
|
||||
try
|
||||
{
|
||||
int var3 = 0;
|
||||
|
||||
if (par2 + this.bufOff > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short for doFinal()");
|
||||
}
|
||||
|
||||
if (this.bufOff != 0)
|
||||
{
|
||||
if (!this.partialBlockOkay)
|
||||
{
|
||||
throw new DataLengthException("data not block size aligned");
|
||||
}
|
||||
|
||||
this.cipher.processBlock(this.buf, 0, this.buf, 0);
|
||||
var3 = this.bufOff;
|
||||
this.bufOff = 0;
|
||||
System.arraycopy(this.buf, 0, par1ArrayOfByte, par2, var3);
|
||||
}
|
||||
|
||||
var4 = var3;
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.reset();
|
||||
}
|
||||
|
||||
return var4;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
for (int var1 = 0; var1 < this.buf.length; ++var1)
|
||||
{
|
||||
this.buf[var1] = 0;
|
||||
}
|
||||
|
||||
this.bufOff = 0;
|
||||
this.cipher.reset();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CipherKeyGenerator
|
||||
{
|
||||
protected Random random;
|
||||
protected int strength;
|
||||
|
||||
public void init(KeyGenerationParameters par1)
|
||||
{
|
||||
this.random = par1.getRandom();
|
||||
this.strength = (par1.getStrength() + 7) / 8;
|
||||
}
|
||||
|
||||
public byte[] generateKey()
|
||||
{
|
||||
byte[] var1 = new byte[this.strength];
|
||||
this.random.nextBytes(var1);
|
||||
return var1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface CipherParameters
|
||||
{
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class DataLengthException extends RuntimeCryptoException
|
||||
{
|
||||
public DataLengthException() {}
|
||||
|
||||
public DataLengthException(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class KeyGenerationParameters
|
||||
{
|
||||
private Random random;
|
||||
private int strength;
|
||||
|
||||
public KeyGenerationParameters(Random par1SecureRandom, int par2)
|
||||
{
|
||||
this.random = par1SecureRandom;
|
||||
this.strength = par2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the random source associated with this generator.
|
||||
*/
|
||||
public Random getRandom()
|
||||
{
|
||||
return this.random;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bit strength for keys produced by this generator.
|
||||
*/
|
||||
public int getStrength()
|
||||
{
|
||||
return this.strength;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public class RuntimeCryptoException extends RuntimeException
|
||||
{
|
||||
public RuntimeCryptoException() {}
|
||||
|
||||
public RuntimeCryptoException(String par1Str)
|
||||
{
|
||||
super(par1Str);
|
||||
}
|
||||
}
|
11
src/teavm/java/org/bouncycastle/crypto/StreamCipher.java
Normal file
11
src/teavm/java/org/bouncycastle/crypto/StreamCipher.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface StreamCipher
|
||||
{
|
||||
/**
|
||||
* Encrypt/decrypt a single byte, returning the result.
|
||||
*/
|
||||
byte returnByte(byte var1);
|
||||
|
||||
void processBytes(byte[] var1, int var2, int var3, byte[] var4, int var5) throws DataLengthException;
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
package org.bouncycastle.crypto.engines;
|
||||
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
public class AESFastEngine implements BlockCipher
|
||||
{
|
||||
private static final byte[] S = new byte[] {(byte)99, (byte)124, (byte)119, (byte)123, (byte) - 14, (byte)107, (byte)111, (byte) - 59, (byte)48, (byte)1, (byte)103, (byte)43, (byte) - 2, (byte) - 41, (byte) - 85, (byte)118, (byte) - 54, (byte) - 126, (byte) - 55, (byte)125, (byte) - 6, (byte)89, (byte)71, (byte) - 16, (byte) - 83, (byte) - 44, (byte) - 94, (byte) - 81, (byte) - 100, (byte) - 92, (byte)114, (byte) - 64, (byte) - 73, (byte) - 3, (byte) - 109, (byte)38, (byte)54, (byte)63, (byte) - 9, (byte) - 52, (byte)52, (byte) - 91, (byte) - 27, (byte) - 15, (byte)113, (byte) - 40, (byte)49, (byte)21, (byte)4, (byte) - 57, (byte)35, (byte) - 61, (byte)24, (byte) - 106, (byte)5, (byte) - 102, (byte)7, (byte)18, (byte) - 128, (byte) - 30, (byte) - 21, (byte)39, (byte) - 78, (byte)117, (byte)9, (byte) - 125, (byte)44, (byte)26, (byte)27, (byte)110, (byte)90, (byte) - 96, (byte)82, (byte)59, (byte) - 42, (byte) - 77, (byte)41, (byte) - 29, (byte)47, (byte) - 124, (byte)83, (byte) - 47, (byte)0, (byte) - 19, (byte)32, (byte) - 4, (byte) - 79, (byte)91, (byte)106, (byte) - 53, (byte) - 66, (byte)57, (byte)74, (byte)76, (byte)88, (byte) - 49, (byte) - 48, (byte) - 17, (byte) - 86, (byte) - 5, (byte)67, (byte)77, (byte)51, (byte) - 123, (byte)69, (byte) - 7, (byte)2, (byte)127, (byte)80, (byte)60, (byte) - 97, (byte) - 88, (byte)81, (byte) - 93, (byte)64, (byte) - 113, (byte) - 110, (byte) - 99, (byte)56, (byte) - 11, (byte) - 68, (byte) - 74, (byte) - 38, (byte)33, (byte)16, (byte) - 1, (byte) - 13, (byte) - 46, (byte) - 51, (byte)12, (byte)19, (byte) - 20, (byte)95, (byte) - 105, (byte)68, (byte)23, (byte) - 60, (byte) - 89, (byte)126, (byte)61, (byte)100, (byte)93, (byte)25, (byte)115, (byte)96, (byte) - 127, (byte)79, (byte) - 36, (byte)34, (byte)42, (byte) - 112, (byte) - 120, (byte)70, (byte) - 18, (byte) - 72, (byte)20, (byte) - 34, (byte)94, (byte)11, (byte) - 37, (byte) - 32, (byte)50, (byte)58, (byte)10, (byte)73, (byte)6, (byte)36, (byte)92, (byte) - 62, (byte) - 45, (byte) - 84, (byte)98, (byte) - 111, (byte) - 107, (byte) - 28, (byte)121, (byte) - 25, (byte) - 56, (byte)55, (byte)109, (byte) - 115, (byte) - 43, (byte)78, (byte) - 87, (byte)108, (byte)86, (byte) - 12, (byte) - 22, (byte)101, (byte)122, (byte) - 82, (byte)8, (byte) - 70, (byte)120, (byte)37, (byte)46, (byte)28, (byte) - 90, (byte) - 76, (byte) - 58, (byte) - 24, (byte) - 35, (byte)116, (byte)31, (byte)75, (byte) - 67, (byte) - 117, (byte) - 118, (byte)112, (byte)62, (byte) - 75, (byte)102, (byte)72, (byte)3, (byte) - 10, (byte)14, (byte)97, (byte)53, (byte)87, (byte) - 71, (byte) - 122, (byte) - 63, (byte)29, (byte) - 98, (byte) - 31, (byte) - 8, (byte) - 104, (byte)17, (byte)105, (byte) - 39, (byte) - 114, (byte) - 108, (byte) - 101, (byte)30, (byte) - 121, (byte) - 23, (byte) - 50, (byte)85, (byte)40, (byte) - 33, (byte) - 116, (byte) - 95, (byte) - 119, (byte)13, (byte) - 65, (byte) - 26, (byte)66, (byte)104, (byte)65, (byte) - 103, (byte)45, (byte)15, (byte) - 80, (byte)84, (byte) - 69, (byte)22};
|
||||
private static final byte[] Si = new byte[] {(byte)82, (byte)9, (byte)106, (byte) - 43, (byte)48, (byte)54, (byte) - 91, (byte)56, (byte) - 65, (byte)64, (byte) - 93, (byte) - 98, (byte) - 127, (byte) - 13, (byte) - 41, (byte) - 5, (byte)124, (byte) - 29, (byte)57, (byte) - 126, (byte) - 101, (byte)47, (byte) - 1, (byte) - 121, (byte)52, (byte) - 114, (byte)67, (byte)68, (byte) - 60, (byte) - 34, (byte) - 23, (byte) - 53, (byte)84, (byte)123, (byte) - 108, (byte)50, (byte) - 90, (byte) - 62, (byte)35, (byte)61, (byte) - 18, (byte)76, (byte) - 107, (byte)11, (byte)66, (byte) - 6, (byte) - 61, (byte)78, (byte)8, (byte)46, (byte) - 95, (byte)102, (byte)40, (byte) - 39, (byte)36, (byte) - 78, (byte)118, (byte)91, (byte) - 94, (byte)73, (byte)109, (byte) - 117, (byte) - 47, (byte)37, (byte)114, (byte) - 8, (byte) - 10, (byte)100, (byte) - 122, (byte)104, (byte) - 104, (byte)22, (byte) - 44, (byte) - 92, (byte)92, (byte) - 52, (byte)93, (byte)101, (byte) - 74, (byte) - 110, (byte)108, (byte)112, (byte)72, (byte)80, (byte) - 3, (byte) - 19, (byte) - 71, (byte) - 38, (byte)94, (byte)21, (byte)70, (byte)87, (byte) - 89, (byte) - 115, (byte) - 99, (byte) - 124, (byte) - 112, (byte) - 40, (byte) - 85, (byte)0, (byte) - 116, (byte) - 68, (byte) - 45, (byte)10, (byte) - 9, (byte) - 28, (byte)88, (byte)5, (byte) - 72, (byte) - 77, (byte)69, (byte)6, (byte) - 48, (byte)44, (byte)30, (byte) - 113, (byte) - 54, (byte)63, (byte)15, (byte)2, (byte) - 63, (byte) - 81, (byte) - 67, (byte)3, (byte)1, (byte)19, (byte) - 118, (byte)107, (byte)58, (byte) - 111, (byte)17, (byte)65, (byte)79, (byte)103, (byte) - 36, (byte) - 22, (byte) - 105, (byte) - 14, (byte) - 49, (byte) - 50, (byte) - 16, (byte) - 76, (byte) - 26, (byte)115, (byte) - 106, (byte) - 84, (byte)116, (byte)34, (byte) - 25, (byte) - 83, (byte)53, (byte) - 123, (byte) - 30, (byte) - 7, (byte)55, (byte) - 24, (byte)28, (byte)117, (byte) - 33, (byte)110, (byte)71, (byte) - 15, (byte)26, (byte)113, (byte)29, (byte)41, (byte) - 59, (byte) - 119, (byte)111, (byte) - 73, (byte)98, (byte)14, (byte) - 86, (byte)24, (byte) - 66, (byte)27, (byte) - 4, (byte)86, (byte)62, (byte)75, (byte) - 58, (byte) - 46, (byte)121, (byte)32, (byte) - 102, (byte) - 37, (byte) - 64, (byte) - 2, (byte)120, (byte) - 51, (byte)90, (byte) - 12, (byte)31, (byte) - 35, (byte) - 88, (byte)51, (byte) - 120, (byte)7, (byte) - 57, (byte)49, (byte) - 79, (byte)18, (byte)16, (byte)89, (byte)39, (byte) - 128, (byte) - 20, (byte)95, (byte)96, (byte)81, (byte)127, (byte) - 87, (byte)25, (byte) - 75, (byte)74, (byte)13, (byte)45, (byte) - 27, (byte)122, (byte) - 97, (byte) - 109, (byte) - 55, (byte) - 100, (byte) - 17, (byte) - 96, (byte) - 32, (byte)59, (byte)77, (byte) - 82, (byte)42, (byte) - 11, (byte) - 80, (byte) - 56, (byte) - 21, (byte) - 69, (byte)60, (byte) - 125, (byte)83, (byte) - 103, (byte)97, (byte)23, (byte)43, (byte)4, (byte)126, (byte) - 70, (byte)119, (byte) - 42, (byte)38, (byte) - 31, (byte)105, (byte)20, (byte)99, (byte)85, (byte)33, (byte)12, (byte)125};
|
||||
private static final int[] rcon = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154, 47, 94, 188, 99, 198, 151, 53, 106, 212, 179, 125, 250, 239, 197, 145};
|
||||
private static final int[] T0 = new int[] { -1520213050, -2072216328, -1720223762, -1921287178, 234025727, -1117033514, -1318096930, 1422247313, 1345335392, 50397442, -1452841010, 2099981142, 436141799, 1658312629, -424957107, -1703512340, 1170918031, -1652391393, 1086966153, -2021818886, 368769775, -346465870, -918075506, 200339707, -324162239, 1742001331, -39673249, -357585083, -1080255453, -140204973, -1770884380, 1539358875, -1028147339, 486407649, -1366060227, 1780885068, 1513502316, 1094664062, 49805301, 1338821763, 1546925160, -190470831, 887481809, 150073849, -1821281822, 1943591083, 1395732834, 1058346282, 201589768, 1388824469, 1696801606, 1589887901, 672667696, -1583966665, 251987210, -1248159185, 151455502, 907153956, -1686077413, 1038279391, 652995533, 1764173646, -843926913, -1619692054, 453576978, -1635548387, 1949051992, 773462580, 756751158, -1301385508, -296068428, -73359269, -162377052, 1295727478, 1641469623, -827083907, 2066295122, 1055122397, 1898917726, -1752923117, -179088474, 1758581177, 0, 753790401, 1612718144, 536673507, -927878791, -312779850, -1100322092, 1187761037, -641810841, 1262041458, -565556588, -733197160, -396863312, 1255133061, 1808847035, 720367557, -441800113, 385612781, -985447546, -682799718, 1429418854, -1803188975, -817543798, 284817897, 100794884, -2122350594, -263171936, 1144798328, -1163944155, -475486133, -212774494, -22830243, -1069531008, -1970303227, -1382903233, -1130521311, 1211644016, 83228145, -541279133, -1044990345, 1977277103, 1663115586, 806359072, 452984805, 250868733, 1842533055, 1288555905, 336333848, 890442534, 804056259, -513843266, -1567123659, -867941240, 957814574, 1472513171, -223893675, -2105639172, 1195195770, -1402706744, -413311558, 723065138, -1787595802, -1604296512, -1736343271, -783331426, 2145180835, 1713513028, 2116692564, -1416589253, -2088204277, -901364084, 703524551, -742868885, 1007948840, 2044649127, -497131844, 487262998, 1994120109, 1004593371, 1446130276, 1312438900, 503974420, -615954030, 168166924, 1814307912, -463709000, 1573044895, 1859376061, -273896381, -1503501628, -1466855111, -1533700815, 937747667, -1954973198, 854058965, 1137232011, 1496790894, -1217565222, -1936880383, 1691735473, -766620004, -525751991, -1267962664, -95005012, 133494003, 636152527, -1352309302, -1904575756, -374428089, 403179536, -709182865, -2005370640, 1864705354, 1915629148, 605822008, -240736681, -944458637, 1371981463, 602466507, 2094914977, -1670089496, 555687742, -582268010, -591544991, -2037675251, -2054518257, -1871679264, 1111375484, -994724495, -1436129588, -666351472, 84083462, 32962295, 302911004, -1553899070, 1597322602, -111716434, -793134743, -1853454825, 1489093017, 656219450, -1180787161, 954327513, 335083755, -1281845205, 856756514, -1150719534, 1893325225, -1987146233, -1483434957, -1231316179, 572399164, -1836611819, 552200649, 1238290055, -11184726, 2015897680, 2061492133, -1886614525, -123625127, -2138470135, 386731290, -624967835, 837215959, -968736124, -1201116976, -1019133566, -1332111063, 1999449434, 286199582, -877612933, -61582168, -692339859, 974525996};
|
||||
private static final int[] T1 = new int[] {1667483301, 2088564868, 2004348569, 2071721613, -218956019, 1802229437, 1869602481, -976907948, 808476752, 16843267, 1734856361, 724260477, -16849127, -673729182, -1414836762, 1987505306, -892694715, -2105401443, -909539008, 2105408135, -84218091, 1499050731, 1195871945, -252642549, -1381154324, -724257945, -1566416899, -1347467798, -1667488833, -1532734473, 1920132246, -1061119141, -1212713534, -33693412, -1819066962, 640044138, 909536346, 1061125697, -134744830, -859012273, 875849820, -1515892236, -437923532, -235800312, 1903288979, -656888973, 825320019, 353708607, 67373068, -943221422, 589514341, -1010590370, 404238376, -1768540255, 84216335, -1701171275, 117902857, 303178806, -2139087973, -488448195, -336868058, 656887401, -1296924723, 1970662047, 151589403, -2088559202, 741103732, 437924910, 454768173, 1852759218, 1515893998, -1600103429, 1381147894, 993752653, -690571423, -1280082482, 690573947, -471605954, 791633521, -2071719017, 1397991157, -774784664, 0, -303185620, 538984544, -50535649, -1313769016, 1532737261, 1785386174, -875852474, -1094817831, 960066123, 1246401758, 1280088276, 1482207464, -808483510, -791626901, -269499094, -1431679003, -67375850, 1128498885, 1296931543, 859006549, -2054876780, 1162185423, -101062384, 33686534, 2139094657, 1347461360, 1010595908, -1616960070, -1465365533, 1364304627, -1549574658, 1077969088, -1886452342, -1835909203, -1650646596, 943222856, -168431356, -1128504353, -1229555775, -623202443, 555827811, 269492272, -6886, -202113778, -757940371, -842170036, 202119188, 320022069, -320027857, 1600110305, -1751698014, 1145342156, 387395129, -993750185, -1482205710, 2122251394, 1027439175, 1684326572, 1566423783, 421081643, 1936975509, 1616953504, -2122245736, 1330618065, -589520001, 572671078, 707417214, -1869595733, -2004350077, 1179028682, -286341335, -1195873325, 336865340, -555833479, 1583267042, 185275933, -606360202, -522134725, 842163286, 976909390, 168432670, 1229558491, 101059594, 606357612, 1549580516, -1027432611, -741098130, -1397996561, 1650640038, -1852753496, -1785384540, -454765769, 2038035083, -404237006, -926381245, 926379609, 1835915959, -1920138868, -707415708, 1313774802, -1448523296, 1819072692, 1448520954, -185273593, -353710299, 1701169839, 2054878350, -1364310039, 134746136, -1162186795, 2021191816, 623200879, 774790258, 471611428, -1499047951, -1263242297, -960063663, -387396829, -572677764, 1953818780, 522141217, 1263245021, -1111662116, -1953821306, -1970663547, 1886445712, 1044282434, -1246400060, 1718013098, 1212715224, 50529797, -151587071, 235805714, 1633796771, 892693087, 1465364217, -1179031088, -2038032495, -1044276904, 488454695, -1633802311, -505292488, -117904621, -1734857805, 286335539, 1768542907, -640046736, -1903294583, -1802226777, -1684329034, 505297954, -2021190254, -370554592, -825325751, 1431677695, 673730680, -538991238, -1936981105, -1583261192, -1987507840, 218962455, -1077975590, -421079247, 1111655622, 1751699640, 1094812355, -1718015568, 757946999, 252648977, -1330611253, 1414834428, -1145344554, 370551866};
|
||||
private static final int[] T2 = new int[] {1673962851, 2096661628, 2012125559, 2079755643, -218165774, 1809235307, 1876865391, -980331323, 811618352, 16909057, 1741597031, 727088427, -18408962, -675978537, -1420958037, 1995217526, -896580150, -2111857278, -913751863, 2113570685, -84994566, 1504897881, 1200539975, -251982864, -1388188499, -726439980, -1570767454, -1354372433, -1675378788, -1538000988, 1927583346, -1063560256, -1217019209, -35578627, -1824674157, 642542118, 913070646, 1065238847, -134937865, -863809588, 879254580, -1521355611, -439274267, -235337487, 1910674289, -659852328, 828527409, 355090197, 67636228, -946515257, 591815971, -1013096765, 405809176, -1774739050, 84545285, -1708149350, 118360327, 304363026, -2145674368, -488686110, -338876693, 659450151, -1300247118, 1978310517, 152181513, -2095210877, 743994412, 439627290, 456535323, 1859957358, 1521806938, -1604584544, 1386542674, 997608763, -692624938, -1283600717, 693271337, -472039709, 794718511, -2079090812, 1403450707, -776378159, 0, -306107155, 541089824, -52224004, -1317418831, 1538714971, 1792327274, -879933749, -1100490306, 963791673, 1251270218, 1285084236, 1487988824, -813348145, -793023536, -272291089, -1437604438, -68348165, 1132905795, 1301993293, 862344499, -2062445435, 1166724933, -102166279, 33818114, 2147385727, 1352724560, 1014514748, -1624917345, -1471421528, 1369633617, -1554121053, 1082179648, -1895462257, -1841320558, -1658733411, 946882616, -168753931, -1134305348, -1233665610, -626035238, 557998881, 270544912, -1762561, -201519373, -759206446, -847164211, 202904588, 321271059, -322752532, 1606345055, -1758092649, 1149815876, 388905239, -996976700, -1487539545, 2130477694, 1031423805, 1690872932, 1572530013, 422718233, 1944491379, 1623236704, -2129028991, 1335808335, -593264676, 574907938, 710180394, -1875137648, -2012511352, 1183631942, -288937490, -1200893000, 338181140, -559449634, 1589437022, 185998603, -609388837, -522503200, 845436466, 980700730, 169090570, 1234361161, 101452294, 608726052, 1555620956, -1029743166, -742560045, -1404833876, 1657054818, -1858492271, -1791908715, -455919644, 2045938553, -405458201, -930397240, 929978679, 1843050349, -1929278323, -709794603, 1318900302, -1454776151, 1826141292, 1454176854, -185399308, -355523094, 1707781989, 2062847610, -1371018834, 135272456, -1167075910, 2029029496, 625635109, 777810478, 473441308, -1504185946, -1267480652, -963161658, -389340184, -576619299, 1961401460, 524165407, 1268178251, -1117659971, -1962047861, -1978694262, 1893765232, 1048330814, -1250835275, 1724688998, 1217452104, 50726147, -151584266, 236720654, 1640145761, 896163637, 1471084887, -1184247623, -2045275770, -1046914879, 490350365, -1641563746, -505857823, -118811656, -1741966440, 287453969, 1775418217, -643206951, -1912108658, -1808554092, -1691502949, 507257374, -2028629369, -372694807, -829994546, 1437269845, 676362280, -542803233, -1945923700, -1587939167, -1995865975, 219813645, -1083843905, -422104602, 1115997762, 1758509160, 1099088705, -1725321063, 760903469, 253628687, -1334064208, 1420360788, -1150429509, 371997206};
|
||||
private static final int[] T3 = new int[] { -962239645, -125535108, -291932297, -158499973, -15863054, -692229269, -558796945, -1856715323, 1615867952, 33751297, -827758745, 1451043627, -417726722, -1251813417, 1306962859, -325421450, -1891251510, 530416258, -1992242743, -91783811, -283772166, -1293199015, -1899411641, -83103504, 1106029997, -1285040940, 1610457762, 1173008303, 599760028, 1408738468, -459902350, -1688485696, 1975695287, -518193667, 1034851219, 1282024998, 1817851446, 2118205247, -184354825, -2091922228, 1750873140, 1374987685, -785062427, -116854287, -493653647, -1418471208, 1649619249, 708777237, 135005188, -1789737017, 1181033251, -1654733885, 807933976, 933336726, 168756485, 800430746, 235472647, 607523346, 463175808, -549592350, -853087253, 1315514151, 2144187058, -358648459, 303761673, 496927619, 1484008492, 875436570, 908925723, -592286098, -1259447718, 1543217312, -1527360942, 1984772923, -1218324778, 2110698419, 1383803177, -583080989, 1584475951, 328696964, -1493871789, -1184312879, 0, -1054020115, 1080041504, -484442884, 2043195825, -1225958565, -725718422, -1924740149, 1742323390, 1917532473, -1797371318, -1730917300, -1326950312, -2058694705, -1150562096, -987041809, 1340451498, -317260805, -2033892541, -1697166003, 1716859699, 294946181, -1966127803, -384763399, 67502594, -25067649, -1594863536, 2017737788, 632987551, 1273211048, -1561112239, 1576969123, -2134884288, 92966799, 1068339858, 566009245, 1883781176, -251333131, 1675607228, 2009183926, -1351230758, 1113792801, 540020752, -451215361, -49351693, -1083321646, -2125673011, 403966988, 641012499, -1020269332, -1092526241, 899848087, -1999879100, 775493399, -1822964540, 1441965991, -58556802, 2051489085, -928226204, -1159242403, 841685273, -426413197, -1063231392, 429425025, -1630449841, -1551901476, 1147544098, 1417554474, 1001099408, 193169544, -1932900794, -953553170, 1809037496, 675025940, -1485185314, -1126015394, 371002123, -1384719397, -616832800, 1683370546, 1951283770, 337512970, -1831122615, 201983494, 1215046692, -1192993700, -1621245246, -1116810285, 1139780780, -995728798, 967348625, 832869781, -751311644, -225740423, -718084121, -1958491960, 1851340599, -625513107, 25988493, -1318791723, -1663938994, 1239460265, -659264404, -1392880042, -217582348, -819598614, -894474907, -191989126, 1206496942, 270010376, 1876277946, -259491720, 1248797989, 1550986798, 941890588, 1475454630, 1942467764, -1756248378, -886839064, -1585652259, -392399756, 1042358047, -1763882165, 1641856445, 226921355, 260409994, -527404944, 2084716094, 1908716981, -861247898, -1864873912, 100991747, -150866186, 470945294, -1029480095, 1784624437, -1359390889, 1775286713, 395413126, -1722236479, 975641885, 666476190, -650583583, -351012616, 733190296, 573772049, -759469719, -1452221991, 126455438, 866620564, 766942107, 1008868894, 361924487, -920589847, -2025206066, -1426107051, 1350051880, -1518673953, 59739276, 1509466529, 159418761, 437718285, 1708834751, -684595482, -2067381694, -793221016, -2101132991, 699439513, 1517759789, 504434447, 2076946608, -1459858348, 1842789307, 742004246};
|
||||
private static final int[] Tinv0 = new int[] {1353184337, 1399144830, -1012656358, -1772214470, -882136261, -247096033, -1420232020, -1828461749, 1442459680, -160598355, -1854485368, 625738485, -52959921, -674551099, -2143013594, -1885117771, 1230680542, 1729870373, -1743852987, -507445667, 41234371, 317738113, -1550367091, -956705941, -413167869, -1784901099, -344298049, -631680363, 763608788, -752782248, 694804553, 1154009486, 1787413109, 2021232372, 1799248025, -579749593, -1236278850, 397248752, 1722556617, -1271214467, 407560035, -2110711067, 1613975959, 1165972322, -529046351, -2068943941, 480281086, -1809118983, 1483229296, 436028815, -2022908268, -1208452270, 601060267, -503166094, 1468997603, 715871590, 120122290, 63092015, -1703164538, -1526188077, -226023376, -1297760477, -1167457534, 1552029421, 723308426, -1833666137, -252573709, -1578997426, -839591323, -708967162, 526529745, -1963022652, -1655493068, -1604979806, 853641733, 1978398372, 971801355, -1427152832, 111112542, 1360031421, -108388034, 1023860118, -1375387939, 1186850381, -1249028975, 90031217, 1876166148, -15380384, 620468249, -1746289194, -868007799, 2006899047, -1119688528, -2004121337, 945494503, -605108103, 1191869601, -384875908, -920746760, 0, -2088337399, 1223502642, -1401941730, 1316117100, -67170563, 1446544655, 517320253, 658058550, 1691946762, 564550760, -783000677, 976107044, -1318647284, 266819475, -761860428, -1634624741, 1338359936, -1574904735, 1766553434, 370807324, 179999714, -450191168, 1138762300, 488053522, 185403662, -1379431438, -1180125651, -928440812, -2061897385, 1275557295, -1143105042, -44007517, -1624899081, -1124765092, -985962940, 880737115, 1982415755, -590994485, 1761406390, 1676797112, -891538985, 277177154, 1076008723, 538035844, 2099530373, -130171950, 288553390, 1839278535, 1261411869, -214912292, -330136051, -790380169, 1813426987, -1715900247, -95906799, 577038663, -997393240, 440397984, -668172970, -275762398, -951170681, -1043253031, -22885748, 906744984, -813566554, 685669029, 646887386, -1530942145, -459458004, 227702864, -1681105046, 1648787028, -1038905866, -390539120, 1593260334, -173030526, -1098883681, 2090061929, -1456614033, -1290656305, 999926984, -1484974064, 1852021992, 2075868123, 158869197, -199730834, 28809964, -1466282109, 1701746150, 2129067946, 147831841, -420997649, -644094022, -835293366, -737566742, -696471511, -1347247055, 824393514, 815048134, -1067015627, 935087732, -1496677636, -1328508704, 366520115, 1251476721, -136647615, 240176511, 804688151, -1915335306, 1303441219, 1414376140, -553347356, -474623586, 461924940, -1205916479, 2136040774, 82468509, 1563790337, 1937016826, 776014843, 1511876531, 1389550482, 861278441, 323475053, -1939744870, 2047648055, -1911228327, -1992551445, -299390514, 902390199, -303751967, 1018251130, 1507840668, 1064563285, 2043548696, -1086863501, -355600557, 1537932639, 342834655, -2032450440, -2114736182, 1053059257, 741614648, 1598071746, 1925389590, 203809468, -1958134744, 1100287487, 1895934009, -558691320, -1662733096, -1866377628, 1636092795, 1890988757, 1952214088, 1113045200};
|
||||
private static final int[] Tinv1 = new int[] { -1477160624, 1698790995, -1541989693, 1579629206, 1806384075, 1167925233, 1492823211, 65227667, -97509291, 1836494326, 1993115793, 1275262245, -672837636, -886389289, 1144333952, -1553812081, 1521606217, 465184103, 250234264, -1057071647, 1966064386, -263421678, -1756983901, -103584826, 1603208167, -1668147819, 2054012907, 1498584538, -2084645843, 561273043, 1776306473, -926314940, -1983744662, 2039411832, 1045993835, 1907959773, 1340194486, -1383534569, -1407137434, 986611124, 1256153880, 823846274, 860985184, 2136171077, 2003087840, -1368671356, -1602093540, 722008468, 1749577816, -45773031, 1826526343, -126135625, -747394269, 38499042, -1893735593, -1420466646, 686535175, -1028313341, 2076542618, 137876389, -2027409166, -1514200142, 1778582202, -2112426660, 483363371, -1267095662, -234359824, -496415071, -187013683, -1106966827, 1647628575, -22625142, 1395537053, 1442030240, -511048398, -336157579, -326956231, -278904662, -1619960314, 275692881, -1977532679, 115185213, 88006062, -1108980410, -1923837515, 1573155077, -737803153, 357589247, -73918172, -373434729, 1128303052, -1629919369, 1122545853, -1953953912, 1528424248, -288851493, 175939911, 256015593, 512030921, 0, -2038429309, -315936184, 1880170156, 1918528590, -15794693, 948244310, -710001378, 959264295, -653325724, -1503893471, 1415289809, 775300154, 1728711857, -413691121, -1762741038, -1852105826, -977239985, 551313826, 1266113129, 437394454, -1164713462, 715178213, -534627261, 387650077, 218697227, -947129683, -1464455751, -1457646392, 435246981, 125153100, -577114437, 1618977789, 637663135, -177054532, 996558021, 2130402100, 692292470, -970732580, -51530136, -236668829, -600713270, -2057092592, 580326208, 298222624, 608863613, 1035719416, 855223825, -1591097491, 798891339, 817028339, 1384517100, -473860144, 380840812, -1183798887, 1217663482, 1693009698, -1929598780, 1072734234, 746411736, -1875696913, 1313441735, -784803391, -1563783938, 198481974, -2114607409, -562387672, -1900553690, -1079165020, -1657131804, -1837608947, -866162021, 1182684258, 328070850, -1193766680, -147247522, -1346141451, -2141347906, -1815058052, 768962473, 304467891, -1716729797, 2098729127, 1671227502, -1153705093, 2015808777, 408514292, -1214583807, -1706064984, 1855317605, -419452290, -809754360, -401215514, -1679312167, 913263310, 161475284, 2091919830, -1297862225, 591342129, -1801075152, 1721906624, -1135709129, -897385306, -795811664, -660131051, -1744506550, -622050825, 1355644686, -158263505, -699566451, -1326496947, 1303039060, 76997855, -1244553501, -2006299621, 523026872, 1365591679, -362898172, 898367837, 1955068531, 1091304238, 493335386, -757362094, 1443948851, 1205234963, 1641519756, 211892090, 351820174, 1007938441, 665439982, -916342987, -451091987, -1320715716, -539845543, 1945261375, -837543815, 935818175, -839429142, -1426235557, 1866325780, -616269690, -206583167, -999769794, 874788908, 1084473951, -1021503886, 635616268, 1228679307, -1794244799, 27801969, -1291056930, -457910116, -1051302768, -2067039391, -1238182544, 1550600308, 1471729730};
|
||||
private static final int[] Tinv2 = new int[] { -195997529, 1098797925, 387629988, 658151006, -1422144661, -1658851003, -89347240, -481586429, 807425530, 1991112301, -863465098, 49620300, -447742761, 717608907, 891715652, 1656065955, -1310832294, -1171953893, -364537842, -27401792, 801309301, 1283527408, 1183687575, -747911431, -1895569569, -1844079204, 1841294202, 1385552473, -1093390973, 1951978273, -532076183, -913423160, -1032492407, -1896580999, 1486449470, -1188569743, -507595185, -1997531219, 550069932, -830622662, -547153846, 451248689, 1368875059, 1398949247, 1689378935, 1807451310, -2114052960, 150574123, 1215322216, 1167006205, -560691348, 2069018616, 1940595667, 1265820162, 534992783, 1432758955, -340654296, -1255210046, -981034373, 936617224, 674296455, -1088179547, 50510442, 384654466, -813028580, 2041025204, 133427442, 1766760930, -630862348, 84334014, 886120290, -1497068802, 775200083, -207445931, -1979370783, -156994069, -2096416276, 1614850799, 1901987487, 1857900816, 557775242, -577356538, 1054715397, -431143235, 1418835341, -999226019, 100954068, 1348534037, -1743182597, -1110009879, 1082772547, -647530594, -391070398, -1995994997, 434583643, -931537938, 2090944266, 1115482383, -2064070370, 0, -2146860154, 724715757, 287222896, 1517047410, 251526143, -2062592456, -1371726123, 758523705, 252339417, 1550328230, 1536938324, 908343854, 168604007, 1469255655, -290139498, -1692688751, -1065332795, -597581280, 2002413899, 303830554, -1813902662, -1597971158, 574374880, 454171927, 151915277, -1947030073, -1238517336, 504678569, -245922535, 1974422535, -1712407587, 2141453664, 33005350, 1918680309, 1715782971, -77908866, 1133213225, 600562886, -306812676, -457677839, 836225756, 1665273989, -1760346078, -964419567, 1250262308, -1143801795, -106032846, 700935585, -1642247377, -1294142672, -2045907886, -1049112349, -1288999914, 1890163129, -1810761144, -381214108, -56048500, -257942977, 2102843436, 857927568, 1233635150, 953795025, -896729438, -728222197, -173617279, 2057644254, -1210440050, -1388337985, 976020637, 2018512274, 1600822220, 2119459398, -1913208301, -661591880, 959340279, -1014827601, 1570750080, -798393197, -714102483, 634368786, -1396163687, 403744637, -1662488989, 1004239803, 650971512, 1500443672, -1695809097, 1334028442, -1780062866, -5603610, -1138685745, 368043752, -407184997, 1867173430, -1612000247, -1339435396, -1540247630, 1059729699, -1513738092, -1573535642, 1316239292, -2097371446, -1864322864, -1489824296, 82922136, -331221030, -847311280, -1860751370, 1299615190, -280801872, -1429449651, -1763385596, -778116171, 1783372680, 750893087, 1699118929, 1587348714, -1946067659, -2013629580, 201010753, 1739807261, -611167534, 283718486, -697494713, -677737375, -1590199796, -128348652, 334203196, -1446056409, 1639396809, 484568549, 1199193265, -761505313, -229294221, 337148366, -948715721, -145495347, -44082262, 1038029935, 1148749531, -1345682957, 1756970692, 607661108, -1547542720, 488010435, -490992603, 1009290057, 234832277, -1472630527, 201907891, -1260872476, 1449431233, -881106556, 852848822, 1816687708, -1194311081};
|
||||
private static final int[] Tinv3 = new int[] {1364240372, 2119394625, 449029143, 982933031, 1003187115, 535905693, -1398056710, 1267925987, 542505520, -1376359050, -2003732788, -182105086, 1341970405, -975713494, 645940277, -1248877726, -565617999, 627514298, 1167593194, 1575076094, -1023249105, -2129465268, -1918658746, 1808202195, 65494927, 362126482, -1075086739, -1780852398, -735214658, 1490231668, 1227450848, -1908094775, 1969916354, -193431154, -1721024936, 668823993, -1095348255, -266883704, -916018144, 2108963534, 1662536415, -444452582, -1755303087, 1648721747, -1310689436, -1148932501, -31678335, -107730168, 1884842056, -1894122171, -1803064098, 1387788411, -1423715469, 1927414347, -480800993, 1714072405, -1308153621, 788775605, -2036696123, -744159177, 821200680, 598910399, 45771267, -312704490, -1976886065, -1483557767, -202313209, 1319232105, 1707996378, 114671109, -786472396, -997523802, 882725678, -1566550541, 87220618, -1535775754, 188345475, 1084944224, 1577492337, -1118760850, 1056541217, -1774385443, -575797954, 1296481766, -1850372780, 1896177092, 74437638, 1627329872, 421854104, -694687299, -1983102144, 1735892697, -1329773848, 126389129, -415737063, 2044456648, -1589179780, 2095648578, -121037180, 0, 159614592, 843640107, 514617361, 1817080410, -33816818, 257308805, 1025430958, 908540205, 174381327, 1747035740, -1680780197, 607792694, 212952842, -1827674281, -1261267218, 463376795, -2142255680, 1638015196, 1516850039, 471210514, -502613357, -1058723168, 1011081250, 303896347, 235605257, -223492213, 767142070, 348694814, 1468340721, -1353971851, -289677927, -1543675777, -140564991, 1555887474, 1153776486, 1530167035, -1955190461, -874723805, -1234633491, -1201409564, -674571215, 1108378979, 322970263, -2078273082, -2055396278, -755483205, -1374604551, -949116631, 491466654, -588042062, 233591430, 2010178497, 728503987, -1449543312, 301615252, 1193436393, -1463513860, -1608892432, 1457007741, 586125363, -2016981431, -641609416, -1929469238, -1741288492, -1496350219, -1524048262, -635007305, 1067761581, 753179962, 1343066744, 1788595295, 1415726718, -155053171, -1863796520, 777975609, -2097827901, -1614905251, 1769771984, 1873358293, -810347995, -935618132, 279411992, -395418724, -612648133, -855017434, 1861490777, -335431782, -2086102449, -429560171, -1434523905, 554225596, -270079979, -1160143897, 1255028335, -355202657, 701922480, 833598116, 707863359, -969894747, 901801634, 1949809742, -56178046, -525283184, 857069735, -246769660, 1106762476, 2131644621, 389019281, 1989006925, 1129165039, -866890326, -455146346, -1629243951, 1276872810, -1044898004, 1182749029, -1660622242, 22885772, -93096825, -80854773, -1285939865, -1840065829, -382511600, 1829980118, -1702075945, 930745505, 1502483704, -343327725, -823253079, -1221211807, -504503012, 2050797895, -1671831598, 1430221810, 410635796, 1941911495, 1407897079, 1599843069, -552308931, 2022103876, -897453137, -1187068824, 942421028, -1033944925, 376619805, -1140054558, 680216892, -12479219, 963707304, 148812556, -660806476, 1687208278, 2069988555, -714033614, 1215585388, -800958536};
|
||||
private int ROUNDS;
|
||||
private int[][] WorkingKey = (int[][])null;
|
||||
private int C0;
|
||||
private int C1;
|
||||
private int C2;
|
||||
private int C3;
|
||||
private boolean forEncryption;
|
||||
|
||||
private int shift(int par1, int par2)
|
||||
{
|
||||
return par1 >>> par2 | par1 << -par2;
|
||||
}
|
||||
|
||||
private int FFmulX(int par1)
|
||||
{
|
||||
return (par1 & 2139062143) << 1 ^ ((par1 & -2139062144) >>> 7) * 27;
|
||||
}
|
||||
|
||||
private int inv_mcol(int par1)
|
||||
{
|
||||
int var2 = this.FFmulX(par1);
|
||||
int var3 = this.FFmulX(var2);
|
||||
int var4 = this.FFmulX(var3);
|
||||
int var5 = par1 ^ var4;
|
||||
return var2 ^ var3 ^ var4 ^ this.shift(var2 ^ var5, 8) ^ this.shift(var3 ^ var5, 16) ^ this.shift(var5, 24);
|
||||
}
|
||||
|
||||
private int subWord(int par1)
|
||||
{
|
||||
return S[par1 & 255] & 255 | (S[par1 >> 8 & 255] & 255) << 8 | (S[par1 >> 16 & 255] & 255) << 16 | S[par1 >> 24 & 255] << 24;
|
||||
}
|
||||
|
||||
private int[][] generateWorkingKey(byte[] par1ArrayOfByte, boolean par2)
|
||||
{
|
||||
int var3 = par1ArrayOfByte.length / 4;
|
||||
|
||||
if ((var3 == 4 || var3 == 6 || var3 == 8) && var3 * 4 == par1ArrayOfByte.length)
|
||||
{
|
||||
this.ROUNDS = var3 + 6;
|
||||
int[][] var5 = new int[this.ROUNDS + 1][4];
|
||||
int var4 = 0;
|
||||
int var6;
|
||||
|
||||
for (var6 = 0; var6 < par1ArrayOfByte.length; ++var4)
|
||||
{
|
||||
var5[var4 >> 2][var4 & 3] = par1ArrayOfByte[var6] & 255 | (par1ArrayOfByte[var6 + 1] & 255) << 8 | (par1ArrayOfByte[var6 + 2] & 255) << 16 | par1ArrayOfByte[var6 + 3] << 24;
|
||||
var6 += 4;
|
||||
}
|
||||
|
||||
int var7 = this.ROUNDS + 1 << 2;
|
||||
int var8;
|
||||
|
||||
for (var6 = var3; var6 < var7; ++var6)
|
||||
{
|
||||
var8 = var5[var6 - 1 >> 2][var6 - 1 & 3];
|
||||
|
||||
if (var6 % var3 == 0)
|
||||
{
|
||||
var8 = this.subWord(this.shift(var8, 8)) ^ rcon[var6 / var3 - 1];
|
||||
}
|
||||
else if (var3 > 6 && var6 % var3 == 4)
|
||||
{
|
||||
var8 = this.subWord(var8);
|
||||
}
|
||||
|
||||
var5[var6 >> 2][var6 & 3] = var5[var6 - var3 >> 2][var6 - var3 & 3] ^ var8;
|
||||
}
|
||||
|
||||
if (!par2)
|
||||
{
|
||||
for (var8 = 1; var8 < this.ROUNDS; ++var8)
|
||||
{
|
||||
for (var6 = 0; var6 < 4; ++var6)
|
||||
{
|
||||
var5[var8][var6] = this.inv_mcol(var5[var8][var6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return var5;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Key length not 128/192/256 bits.");
|
||||
}
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
if (par2CipherParameters instanceof KeyParameter)
|
||||
{
|
||||
this.WorkingKey = this.generateWorkingKey(((KeyParameter)par2CipherParameters).getKey(), par1);
|
||||
this.forEncryption = par1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("invalid parameter passed to AES init - " + par2CipherParameters.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
public String getAlgorithmName()
|
||||
{
|
||||
return "AES";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
public int getBlockSize()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public int processBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (this.WorkingKey == null)
|
||||
{
|
||||
throw new IllegalStateException("AES engine not initialised");
|
||||
}
|
||||
else if (par2 + 16 > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + 16 > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.forEncryption)
|
||||
{
|
||||
this.unpackBlock(par1ArrayOfByte, par2);
|
||||
this.encryptBlock(this.WorkingKey);
|
||||
this.packBlock(par3ArrayOfByte, par4);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.unpackBlock(par1ArrayOfByte, par2);
|
||||
this.decryptBlock(this.WorkingKey);
|
||||
this.packBlock(par3ArrayOfByte, par4);
|
||||
}
|
||||
|
||||
return 16;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {}
|
||||
|
||||
private void unpackBlock(byte[] par1ArrayOfByte, int par2)
|
||||
{
|
||||
int var3 = par2 + 1;
|
||||
this.C0 = par1ArrayOfByte[par2] & 255;
|
||||
this.C0 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C0 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C0 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C1 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C1 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C1 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C1 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C2 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C2 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C2 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C2 |= par1ArrayOfByte[var3++] << 24;
|
||||
this.C3 = par1ArrayOfByte[var3++] & 255;
|
||||
this.C3 |= (par1ArrayOfByte[var3++] & 255) << 8;
|
||||
this.C3 |= (par1ArrayOfByte[var3++] & 255) << 16;
|
||||
this.C3 |= par1ArrayOfByte[var3++] << 24;
|
||||
}
|
||||
|
||||
private void packBlock(byte[] par1ArrayOfByte, int par2)
|
||||
{
|
||||
int var3 = par2 + 1;
|
||||
par1ArrayOfByte[par2] = (byte)this.C0;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C0 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C1;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C1 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C2;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C2 >> 24);
|
||||
par1ArrayOfByte[var3++] = (byte)this.C3;
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 8);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 16);
|
||||
par1ArrayOfByte[var3++] = (byte)(this.C3 >> 24);
|
||||
}
|
||||
|
||||
private void encryptBlock(int[][] par1ArrayOfInteger)
|
||||
{
|
||||
this.C0 ^= par1ArrayOfInteger[0][0];
|
||||
this.C1 ^= par1ArrayOfInteger[0][1];
|
||||
this.C2 ^= par1ArrayOfInteger[0][2];
|
||||
this.C3 ^= par1ArrayOfInteger[0][3];
|
||||
int var2;
|
||||
int var3;
|
||||
int var4;
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var2 = 1; var2 < this.ROUNDS - 1; this.C3 = T0[var6 & 255] ^ T1[var3 >> 8 & 255] ^ T2[var4 >> 16 & 255] ^ T3[var5 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3])
|
||||
{
|
||||
var3 = T0[this.C0 & 255] ^ T1[this.C1 >> 8 & 255] ^ T2[this.C2 >> 16 & 255] ^ T3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
var4 = T0[this.C1 & 255] ^ T1[this.C2 >> 8 & 255] ^ T2[this.C3 >> 16 & 255] ^ T3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
var5 = T0[this.C2 & 255] ^ T1[this.C3 >> 8 & 255] ^ T2[this.C0 >> 16 & 255] ^ T3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
var6 = T0[this.C3 & 255] ^ T1[this.C0 >> 8 & 255] ^ T2[this.C1 >> 16 & 255] ^ T3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3];
|
||||
this.C0 = T0[var3 & 255] ^ T1[var4 >> 8 & 255] ^ T2[var5 >> 16 & 255] ^ T3[var6 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
this.C1 = T0[var4 & 255] ^ T1[var5 >> 8 & 255] ^ T2[var6 >> 16 & 255] ^ T3[var3 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
this.C2 = T0[var5 & 255] ^ T1[var6 >> 8 & 255] ^ T2[var3 >> 16 & 255] ^ T3[var4 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
}
|
||||
|
||||
var3 = T0[this.C0 & 255] ^ T1[this.C1 >> 8 & 255] ^ T2[this.C2 >> 16 & 255] ^ T3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var2][0];
|
||||
var4 = T0[this.C1 & 255] ^ T1[this.C2 >> 8 & 255] ^ T2[this.C3 >> 16 & 255] ^ T3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var2][1];
|
||||
var5 = T0[this.C2 & 255] ^ T1[this.C3 >> 8 & 255] ^ T2[this.C0 >> 16 & 255] ^ T3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var2][2];
|
||||
var6 = T0[this.C3 & 255] ^ T1[this.C0 >> 8 & 255] ^ T2[this.C1 >> 16 & 255] ^ T3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var2++][3];
|
||||
this.C0 = S[var3 & 255] & 255 ^ (S[var4 >> 8 & 255] & 255) << 8 ^ (S[var5 >> 16 & 255] & 255) << 16 ^ S[var6 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][0];
|
||||
this.C1 = S[var4 & 255] & 255 ^ (S[var5 >> 8 & 255] & 255) << 8 ^ (S[var6 >> 16 & 255] & 255) << 16 ^ S[var3 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][1];
|
||||
this.C2 = S[var5 & 255] & 255 ^ (S[var6 >> 8 & 255] & 255) << 8 ^ (S[var3 >> 16 & 255] & 255) << 16 ^ S[var4 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][2];
|
||||
this.C3 = S[var6 & 255] & 255 ^ (S[var3 >> 8 & 255] & 255) << 8 ^ (S[var4 >> 16 & 255] & 255) << 16 ^ S[var5 >> 24 & 255] << 24 ^ par1ArrayOfInteger[var2][3];
|
||||
}
|
||||
|
||||
private void decryptBlock(int[][] par1ArrayOfInteger)
|
||||
{
|
||||
this.C0 ^= par1ArrayOfInteger[this.ROUNDS][0];
|
||||
this.C1 ^= par1ArrayOfInteger[this.ROUNDS][1];
|
||||
this.C2 ^= par1ArrayOfInteger[this.ROUNDS][2];
|
||||
this.C3 ^= par1ArrayOfInteger[this.ROUNDS][3];
|
||||
int var2;
|
||||
int var3;
|
||||
int var4;
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var6 = this.ROUNDS - 1; var6 > 1; this.C3 = Tinv0[var5 & 255] ^ Tinv1[var4 >> 8 & 255] ^ Tinv2[var3 >> 16 & 255] ^ Tinv3[var2 >> 24 & 255] ^ par1ArrayOfInteger[var6--][3])
|
||||
{
|
||||
var2 = Tinv0[this.C0 & 255] ^ Tinv1[this.C3 >> 8 & 255] ^ Tinv2[this.C2 >> 16 & 255] ^ Tinv3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
var3 = Tinv0[this.C1 & 255] ^ Tinv1[this.C0 >> 8 & 255] ^ Tinv2[this.C3 >> 16 & 255] ^ Tinv3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
var4 = Tinv0[this.C2 & 255] ^ Tinv1[this.C1 >> 8 & 255] ^ Tinv2[this.C0 >> 16 & 255] ^ Tinv3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
var5 = Tinv0[this.C3 & 255] ^ Tinv1[this.C2 >> 8 & 255] ^ Tinv2[this.C1 >> 16 & 255] ^ Tinv3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var6--][3];
|
||||
this.C0 = Tinv0[var2 & 255] ^ Tinv1[var5 >> 8 & 255] ^ Tinv2[var4 >> 16 & 255] ^ Tinv3[var3 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
this.C1 = Tinv0[var3 & 255] ^ Tinv1[var2 >> 8 & 255] ^ Tinv2[var5 >> 16 & 255] ^ Tinv3[var4 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
this.C2 = Tinv0[var4 & 255] ^ Tinv1[var3 >> 8 & 255] ^ Tinv2[var2 >> 16 & 255] ^ Tinv3[var5 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
}
|
||||
|
||||
var2 = Tinv0[this.C0 & 255] ^ Tinv1[this.C3 >> 8 & 255] ^ Tinv2[this.C2 >> 16 & 255] ^ Tinv3[this.C1 >> 24 & 255] ^ par1ArrayOfInteger[var6][0];
|
||||
var3 = Tinv0[this.C1 & 255] ^ Tinv1[this.C0 >> 8 & 255] ^ Tinv2[this.C3 >> 16 & 255] ^ Tinv3[this.C2 >> 24 & 255] ^ par1ArrayOfInteger[var6][1];
|
||||
var4 = Tinv0[this.C2 & 255] ^ Tinv1[this.C1 >> 8 & 255] ^ Tinv2[this.C0 >> 16 & 255] ^ Tinv3[this.C3 >> 24 & 255] ^ par1ArrayOfInteger[var6][2];
|
||||
var5 = Tinv0[this.C3 & 255] ^ Tinv1[this.C2 >> 8 & 255] ^ Tinv2[this.C1 >> 16 & 255] ^ Tinv3[this.C0 >> 24 & 255] ^ par1ArrayOfInteger[var6][3];
|
||||
this.C0 = Si[var2 & 255] & 255 ^ (Si[var5 >> 8 & 255] & 255) << 8 ^ (Si[var4 >> 16 & 255] & 255) << 16 ^ Si[var3 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][0];
|
||||
this.C1 = Si[var3 & 255] & 255 ^ (Si[var2 >> 8 & 255] & 255) << 8 ^ (Si[var5 >> 16 & 255] & 255) << 16 ^ Si[var4 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][1];
|
||||
this.C2 = Si[var4 & 255] & 255 ^ (Si[var3 >> 8 & 255] & 255) << 8 ^ (Si[var2 >> 16 & 255] & 255) << 16 ^ Si[var5 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][2];
|
||||
this.C3 = Si[var5 & 255] & 255 ^ (Si[var4 >> 8 & 255] & 255) << 8 ^ (Si[var3 >> 16 & 255] & 255) << 16 ^ Si[var2 >> 24 & 255] << 24 ^ par1ArrayOfInteger[0][3];
|
||||
}
|
||||
}
|
178
src/teavm/java/org/bouncycastle/crypto/io/CipherInputStream.java
Normal file
178
src/teavm/java/org/bouncycastle/crypto/io/CipherInputStream.java
Normal file
|
@ -0,0 +1,178 @@
|
|||
package org.bouncycastle.crypto.io;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
|
||||
public class CipherInputStream extends FilterInputStream
|
||||
{
|
||||
private BufferedBlockCipher theBufferedBlockCipher;
|
||||
private StreamCipher theStreamCipher;
|
||||
private byte[] buf;
|
||||
private byte[] inBuf;
|
||||
private int bufOff;
|
||||
private int maxBuf;
|
||||
private boolean finalized;
|
||||
|
||||
public CipherInputStream(InputStream par1InputStream, BufferedBlockCipher par2BufferedBlockCipher)
|
||||
{
|
||||
super(par1InputStream);
|
||||
this.theBufferedBlockCipher = par2BufferedBlockCipher;
|
||||
this.buf = new byte[par2BufferedBlockCipher.getOutputSize(2048)];
|
||||
this.inBuf = new byte[2048];
|
||||
}
|
||||
|
||||
private int nextChunk() throws IOException
|
||||
{
|
||||
int var1 = super.available();
|
||||
|
||||
if (var1 <= 0)
|
||||
{
|
||||
var1 = 1;
|
||||
}
|
||||
|
||||
if (var1 > this.inBuf.length)
|
||||
{
|
||||
var1 = super.read(this.inBuf, 0, this.inBuf.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
var1 = super.read(this.inBuf, 0, var1);
|
||||
}
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
if (this.finalized)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
this.maxBuf = this.theBufferedBlockCipher.doFinal(this.buf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.maxBuf = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception var4)
|
||||
{
|
||||
throw new IOException("error processing stream: " + var4.toString());
|
||||
}
|
||||
|
||||
this.bufOff = 0;
|
||||
this.finalized = true;
|
||||
|
||||
if (this.bufOff == this.maxBuf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bufOff = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
this.maxBuf = this.theBufferedBlockCipher.processByte(this.inBuf, 0, var1, this.buf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theStreamCipher.processBytes(this.inBuf, 0, var1, this.buf, 0);
|
||||
this.maxBuf = var1;
|
||||
}
|
||||
}
|
||||
catch (Exception var3)
|
||||
{
|
||||
throw new IOException("error processing stream: " + var3.toString());
|
||||
}
|
||||
|
||||
if (this.maxBuf == 0)
|
||||
{
|
||||
return this.nextChunk();
|
||||
}
|
||||
}
|
||||
|
||||
return this.maxBuf;
|
||||
}
|
||||
|
||||
public int read() throws IOException
|
||||
{
|
||||
return this.bufOff == this.maxBuf && this.nextChunk() < 0 ? -1 : this.buf[this.bufOff++] & 255;
|
||||
}
|
||||
|
||||
public int read(byte[] par1ArrayOfByte) throws IOException
|
||||
{
|
||||
return this.read(par1ArrayOfByte, 0, par1ArrayOfByte.length);
|
||||
}
|
||||
|
||||
public int read(byte[] par1ArrayOfByte, int par2, int par3) throws IOException
|
||||
{
|
||||
if (this.bufOff == this.maxBuf && this.nextChunk() < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int var4 = this.maxBuf - this.bufOff;
|
||||
|
||||
if (par3 > var4)
|
||||
{
|
||||
System.arraycopy(this.buf, this.bufOff, par1ArrayOfByte, par2, var4);
|
||||
this.bufOff = this.maxBuf;
|
||||
return var4;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.arraycopy(this.buf, this.bufOff, par1ArrayOfByte, par2, par3);
|
||||
this.bufOff += par3;
|
||||
return par3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long skip(long par1) throws IOException
|
||||
{
|
||||
if (par1 <= 0L)
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
int var3 = this.maxBuf - this.bufOff;
|
||||
|
||||
if (par1 > (long)var3)
|
||||
{
|
||||
this.bufOff = this.maxBuf;
|
||||
return (long)var3;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bufOff += (int)par1;
|
||||
return (long)((int)par1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException
|
||||
{
|
||||
return this.maxBuf - this.bufOff;
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
super.close();
|
||||
}
|
||||
|
||||
public boolean markSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package org.bouncycastle.crypto.io;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
|
||||
public class CipherOutputStream extends FilterOutputStream
|
||||
{
|
||||
private BufferedBlockCipher theBufferedBlockCipher;
|
||||
private StreamCipher theStreamCipher;
|
||||
private byte[] oneByte = new byte[1];
|
||||
private byte[] buf;
|
||||
|
||||
public CipherOutputStream(OutputStream par1OutputStream, BufferedBlockCipher par2BufferedBlockCipher)
|
||||
{
|
||||
super(par1OutputStream);
|
||||
this.theBufferedBlockCipher = par2BufferedBlockCipher;
|
||||
this.buf = new byte[par2BufferedBlockCipher.getBlockSize()];
|
||||
}
|
||||
|
||||
public void write(int par1) throws IOException
|
||||
{
|
||||
this.oneByte[0] = (byte)par1;
|
||||
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
int var2 = this.theBufferedBlockCipher.processByte(this.oneByte, 0, 1, this.buf, 0);
|
||||
|
||||
if (var2 != 0)
|
||||
{
|
||||
this.out.write(this.buf, 0, var2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.out.write(this.theStreamCipher.returnByte((byte)par1));
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] par1) throws IOException
|
||||
{
|
||||
this.write(par1, 0, par1.length);
|
||||
}
|
||||
|
||||
public void write(byte[] par1, int par2, int par3) throws IOException
|
||||
{
|
||||
byte[] var4;
|
||||
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
var4 = new byte[this.theBufferedBlockCipher.getOutputSize(par3)];
|
||||
int var5 = this.theBufferedBlockCipher.processByte(par1, par2, par3, var4, 0);
|
||||
|
||||
if (var5 != 0)
|
||||
{
|
||||
this.out.write(var4, 0, var5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var4 = new byte[par3];
|
||||
this.theStreamCipher.processBytes(par1, par2, par3, var4, 0);
|
||||
this.out.write(var4, 0, par3);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException
|
||||
{
|
||||
super.flush();
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.theBufferedBlockCipher != null)
|
||||
{
|
||||
byte[] var1 = new byte[this.theBufferedBlockCipher.getOutputSize(0)];
|
||||
int var2 = this.theBufferedBlockCipher.doFinal(var1, 0);
|
||||
|
||||
if (var2 != 0)
|
||||
{
|
||||
this.out.write(var1, 0, var2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception var3)
|
||||
{
|
||||
throw new IOException("Error closing stream: " + var3.toString());
|
||||
}
|
||||
|
||||
this.flush();
|
||||
super.close();
|
||||
}
|
||||
}
|
139
src/teavm/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java
Normal file
139
src/teavm/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
package org.bouncycastle.crypto.modes;
|
||||
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
public class CFBBlockCipher implements BlockCipher
|
||||
{
|
||||
private byte[] IV;
|
||||
private byte[] cfbV;
|
||||
private byte[] cfbOutV;
|
||||
private int blockSize;
|
||||
private BlockCipher cipher = null;
|
||||
private boolean encrypting;
|
||||
|
||||
public CFBBlockCipher(BlockCipher par1BlockCipher, int par2)
|
||||
{
|
||||
this.cipher = par1BlockCipher;
|
||||
this.blockSize = par2 / 8;
|
||||
this.IV = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.cfbV = new byte[par1BlockCipher.getBlockSize()];
|
||||
this.cfbOutV = new byte[par1BlockCipher.getBlockSize()];
|
||||
}
|
||||
|
||||
public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
|
||||
{
|
||||
this.encrypting = par1;
|
||||
|
||||
if (par2CipherParameters instanceof ParametersWithIV)
|
||||
{
|
||||
ParametersWithIV var3 = (ParametersWithIV)par2CipherParameters;
|
||||
byte[] var4 = var3.getIV();
|
||||
|
||||
if (var4.length < this.IV.length)
|
||||
{
|
||||
System.arraycopy(var4, 0, this.IV, this.IV.length - var4.length, var4.length);
|
||||
|
||||
for (int var5 = 0; var5 < this.IV.length - var4.length; ++var5)
|
||||
{
|
||||
this.IV[var5] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.arraycopy(var4, 0, this.IV, 0, this.IV.length);
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
if (var3.getParameters() != null)
|
||||
{
|
||||
this.cipher.init(true, var3.getParameters());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.reset();
|
||||
this.cipher.init(true, par2CipherParameters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
public String getAlgorithmName()
|
||||
{
|
||||
return this.cipher.getAlgorithmName() + "/CFB" + this.blockSize * 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block size for this cipher (in bytes).
|
||||
*/
|
||||
public int getBlockSize()
|
||||
{
|
||||
return this.blockSize;
|
||||
}
|
||||
|
||||
public int processBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
return this.encrypting ? this.encryptBlock(par1ArrayOfByte, par2, par3ArrayOfByte, par4) : this.decryptBlock(par1ArrayOfByte, par2, par3ArrayOfByte, par4);
|
||||
}
|
||||
|
||||
public int encryptBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par2 + this.blockSize > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + this.blockSize > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cipher.processBlock(this.cfbV, 0, this.cfbOutV, 0);
|
||||
|
||||
for (int var5 = 0; var5 < this.blockSize; ++var5)
|
||||
{
|
||||
par3ArrayOfByte[par4 + var5] = (byte)(this.cfbOutV[var5] ^ par1ArrayOfByte[par2 + var5]);
|
||||
}
|
||||
|
||||
System.arraycopy(this.cfbV, this.blockSize, this.cfbV, 0, this.cfbV.length - this.blockSize);
|
||||
System.arraycopy(par3ArrayOfByte, par4, this.cfbV, this.cfbV.length - this.blockSize, this.blockSize);
|
||||
return this.blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public int decryptBlock(byte[] par1ArrayOfByte, int par2, byte[] par3ArrayOfByte, int par4) throws DataLengthException, IllegalStateException
|
||||
{
|
||||
if (par2 + this.blockSize > par1ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("input buffer too short");
|
||||
}
|
||||
else if (par4 + this.blockSize > par3ArrayOfByte.length)
|
||||
{
|
||||
throw new DataLengthException("output buffer too short");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cipher.processBlock(this.cfbV, 0, this.cfbOutV, 0);
|
||||
System.arraycopy(this.cfbV, this.blockSize, this.cfbV, 0, this.cfbV.length - this.blockSize);
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.cfbV, this.cfbV.length - this.blockSize, this.blockSize);
|
||||
|
||||
for (int var5 = 0; var5 < this.blockSize; ++var5)
|
||||
{
|
||||
par3ArrayOfByte[par4 + var5] = (byte)(this.cfbOutV[var5] ^ par1ArrayOfByte[par2 + var5]);
|
||||
}
|
||||
|
||||
return this.blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
System.arraycopy(this.IV, 0, this.cfbV, 0, this.IV.length);
|
||||
this.cipher.reset();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class KeyParameter implements CipherParameters
|
||||
{
|
||||
private byte[] key;
|
||||
|
||||
public KeyParameter(byte[] par1ArrayOfByte)
|
||||
{
|
||||
this(par1ArrayOfByte, 0, par1ArrayOfByte.length);
|
||||
}
|
||||
|
||||
public KeyParameter(byte[] par1ArrayOfByte, int par2, int par3)
|
||||
{
|
||||
this.key = new byte[par3];
|
||||
System.arraycopy(par1ArrayOfByte, par2, this.key, 0, par3);
|
||||
}
|
||||
|
||||
public byte[] getKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class ParametersWithIV implements CipherParameters
|
||||
{
|
||||
private byte[] iv;
|
||||
private CipherParameters parameters;
|
||||
|
||||
public ParametersWithIV(CipherParameters par1CipherParameters, byte[] par2ArrayOfByte, int par3, int par4)
|
||||
{
|
||||
this.iv = new byte[par4];
|
||||
this.parameters = par1CipherParameters;
|
||||
System.arraycopy(par2ArrayOfByte, par3, this.iv, 0, par4);
|
||||
}
|
||||
|
||||
public byte[] getIV()
|
||||
{
|
||||
return this.iv;
|
||||
}
|
||||
|
||||
public CipherParameters getParameters()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user