18 Commits
Author SHA1 Message Date
xiao 215af9ea2b fix copyright in license 2026-08-22 01:40:03 +08:00
xiao e65d9376d0 Add license 2026-08-22 01:37:40 +08:00
Xiao 16149a8dec README.md aktualisieren 2026-08-07 03:12:54 +08:00
Xiao 3f93b73ea0 README.md aktualisieren 2026-08-07 03:11:27 +08:00
Xiao 02aa2c8776 Update isNull.java (#44)
ez
2026-07-14 16:10:38 -04:00
Xiao c8e9b50883 fix leak (#43)
- add SLF4J as a dependency in pom.xml
- replace System.out.println with log.warn (prevent leak)
2026-07-14 16:03:52 -04:00
Xiao 273f10a987 Update XACryptoException.java (#41)
#SIMPLEST FIX EVER lmao
2026-07-14 15:50:25 -04:00
Xiao 999c99f166 Update Factories.java (#40) 2026-07-14 15:46:49 -04:00
Xiao f54b14cc9c Update README.md 2026-07-09 22:32:50 -04:00
Xiao 62b2848ab2 this is why you test things, before commiting to main, kids. 2026-07-05 14:08:16 -04:00
Xiao 06504b83d5 whoops! 2026-07-05 14:03:30 -04:00
xiao 9566323ac7 Update pom.xml
i forgot to update this before erelease lol, i changed this right before i compiled but not before commit!
2026-07-04 14:44:27 -04:00
Xiao X c7fe6cc704 Java mirror fix (#20)
* Update ARIAGCM.java

removed reflection-only exceptions

* desc

bulk remove reflection-only

* Update Factories.java

more removal!

* desc

camellia - add block cipher implements + encryptBlock XACryptoException
twofish- add implement for blockcipher

* lot stuff + cleanup
2026-07-04 12:55:11 -04:00
Xiao X c5a5325f19 whoop (#18) 2026-07-04 00:46:25 -04:00
Xiao X ed2e3cd233 forgot2 remove 2026-06-19 21:48:21 -04:00
Xiao X 24053527b1 Ciphers (#17)
* add AES.java additions + Galois.java

* desc

used ECB and ECBExceptionless instead of seperate interfaces. AESECB done

* Twofish ECB developments, moved some files

* twofishecb done

* Update Factories.java

factories.java topology rewrite 👍

* Update Factories.java

fix whitespace + forgot to add AriaGCM + SerpentGCM

* desc

RC6ECB.java placeholders,
LE32.java

* encblk+decblk funcs

* RC6 done

* desc

- move Camellia to seperate
- create CamelliaECB (it sucks, will fix it more after)

* good fixes!

* Rmv 16bfix (#14)

* progress

some progress was made. next commit will be working on Aria.java (its large so may take some time)

* "invalid config"

* Update Aria.java

potential working!

* bugfix

* Sha224 fix (#15)

* Update SHA224.java

potential fix

* Update pom.xml

tested - works now!
the entire fix was adding * 8L to the padding calculator thing xD

* SHA384 is working

LESGO!

* Create SHA512.java

* Sha512 impl (#16)

* desc
* Update SHA512.java

* Update SHA512.java

oookay a bit of opencode and a lot of time later its solved!
2026-06-19 14:44:12 -04:00
Xiao X 91586225c5 Implement SHA224 (#11)
* start of sha224 implements, tho quite simple

* Update pom.xml

just to make it compile main for testing, simplifies the process
2026-06-04 18:12:34 -04:00
xiao da2dd6c11f Delete release.yml
so it compiles completely fine on my computer but not on the github one? very cool
2026-06-04 16:42:22 -04:00
41 changed files with 1217 additions and 306 deletions
-34
View File
@@ -1,34 +0,0 @@
name: Release
on:
push:
tags:
- '*'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 25
cache: maven
- name: Build
run: mvn -B verify
- name: Publish
run: mvn -B deploy
env:
CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
+3 -3
View File
@@ -8,9 +8,9 @@
<inspection_tool class="GrazieStyle" enabled="false" level="STYLE_SUGGESTION" enabled_by_default="false" /> <inspection_tool class="GrazieStyle" enabled="false" level="STYLE_SUGGESTION" enabled_by_default="false" />
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" /> <inspection_tool class="LanguageDetectionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="false" /> <option name="processCode" value="true" />
<option name="processLiterals" value="false" /> <option name="processLiterals" value="true" />
<option name="processComments" value="false" /> <option name="processComments" value="true" />
</inspection_tool> </inspection_tool>
</profile> </profile>
</component> </component>
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2026 Geprivilegieerde Anonimiteit BV
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+5 -3
View File
@@ -1,7 +1,9 @@
A multi-purpose Cryptography library in Java. Working on it day by day, slowly. Someday this will be complete, today is not that day. A multi-purpose Cryptography library in Java. Working on it day by day, slowly. Someday this will be complete, today is not that day.
To be clear, this is **NOT** mean't to be a replacement/alternative to BouncyCastle. Instead, it is meant to include what BouncyCastle does not have. No code was taken from OpenSSL or BouncyCastle for that reason. To be clear, this is **NOT** mean't to be a replacement/alternative to BouncyCastle. Instead, it is meant to include what BouncyCastle does not have. No code was taken from OpenSSL or BouncyCastle for that reason.
### Current Objective: ZekerRijndael (custom encryption sub-library) We are (soon to be) DMCA-protected: https://www.dmca.com/r/8e2yr97
Yes. We will advertise Microsoft products for free via variable names.
Use `setopt interactivecomments` (zsh only) to allow using `#` for comments if you see errors like `zsh: command not found: #` Use `setopt interactivecomments` (zsh only) to allow using `#` for comments if you see errors like `zsh: command not found: #`
@@ -13,6 +15,6 @@ To compile (these commands should work universally):
1. git clone https://github.com/Geprivilegieerde-Anonimiteit-BV/XACrypto.git # download the git repository 1. git clone https://github.com/Geprivilegieerde-Anonimiteit-BV/XACrypto.git # download the git repository
2. cd XACrypto # enter the directory 2. cd XACrypto # enter the directory
3. mvn clean package # compile the package cleanly 3. mvn clean package # first clean the directory, then package it into a jar
You should find the built jar at target/XACrypto-1.0-SNAPSHOT.jar You should find the built jar at target/xacrypto-\<version\>.jar
+20 -1
View File
@@ -8,7 +8,7 @@
<groupId>de.caydenno1.xacrypto</groupId> <groupId>de.caydenno1.xacrypto</groupId>
<artifactId>xacrypto</artifactId> <artifactId>xacrypto</artifactId>
<version>2026.06.04_R2</version> <version>2026.07.04_R1</version>
<name>XACrypto</name> <name>XACrypto</name>
<description>A multi-purpose Cryptography library in Java.</description> <description>A multi-purpose Cryptography library in Java.</description>
@@ -55,6 +55,12 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
@@ -83,6 +89,19 @@
<version>3.14.0</version> <version>3.14.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>de.caydenno1.xacrypto.XACrypto</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
@@ -1,52 +0,0 @@
package de.caydenno1.xacrypto.encryption;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.security.SecureRandom;
import java.util.Base64;
public class AES_GCM {
private static final String AES = "AES";
private static final String AES_GCM = "AES/GCM/NoPadding";
private AES_GCM() {}
public static SecretKey genKey(int bits) throws Exception {
KeyGenerator g = KeyGenerator.getInstance(AES);
g.init(bits);
return g.generateKey();
}
public static String encrypt(String pln, SecretKey k, int TAG, int IV) throws Exception {
byte[] iv = new byte[IV];
new SecureRandom().nextBytes(iv);
Cipher c = Cipher.getInstance(AES_GCM);
c.init(Cipher.ENCRYPT_MODE, k, new GCMParameterSpec(TAG, iv));
byte[] citext = c.doFinal(pln.getBytes());
byte[] comb = new byte[iv.length + citext.length];
System.arraycopy(iv, 0, comb, 0, iv.length);
System.arraycopy(citext, 0, comb, iv.length, citext.length);
return Base64.getEncoder().encodeToString(comb);
}
public static String decrypt(String enc, SecretKey k, int TAG, int IV) throws Exception {
byte[] dat = Base64.getDecoder().decode(enc);
byte[] iv = new byte[IV];
byte[] cit = new byte[dat.length - IV];
System.arraycopy(dat, 0, iv, 0, IV);
System.arraycopy(dat, IV, cit, 0, cit.length);
Cipher ci = Cipher.getInstance(AES_GCM);
ci.init(Cipher.DECRYPT_MODE, k, new GCMParameterSpec(TAG, iv));
return new String(ci.doFinal(cit));
}
}
@@ -4,6 +4,9 @@ public class ROT {
public static int ROTR(int x, int n){ public static int ROTR(int x, int n){
return (x >>> n) | (x << (32 - n)); return (x >>> n) | (x << (32 - n));
} }
public static long ROTR64(long x, int n){
return (x >>> n) | (x << (64 - n));
}
public static int ROTL(int x, int n){ public static int ROTL(int x, int n){
return (x << n) | (x >>> (32 - n)); return (x << n) | (x >>> (32 - n));
} }
@@ -1,6 +1,8 @@
package de.caydenno1.xacrypto.hash.sha; package de.caydenno1.xacrypto.hash.sha;
import de.caydenno1.xacrypto.misc.Constants; import de.caydenno1.xacrypto.misc.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -8,9 +10,10 @@ import static de.caydenno1.xacrypto.hash.sha.Shared.INT2BYTE;
import static de.caydenno1.xacrypto.hash.sha.Shared.hex; import static de.caydenno1.xacrypto.hash.sha.Shared.hex;
public class SHA0 { public class SHA0 {
// we really only need one file. very simple code private static final Logger log = LoggerFactory.getLogger(SHA0.class);
public static byte[] hash(byte[] data){ public static byte[] hash(byte[] data){
System.out.println("Beware, SHA0 is deprecated and cryptographically broken. Use at your own risk."); log.warn("SHA0 is deprecated and cryptographically broken. Use at your own risk.");
byte[] padded = Shared.pad(data); byte[] padded = Shared.pad(data);
int a0 = Constants.SHA_H[0], a1 = Constants.SHA_H[1], a2 = Constants.SHA_H[2], a3 = Constants.SHA_H[3], a4 = Constants.SHA_H[4]; int a0 = Constants.SHA_H[0], a1 = Constants.SHA_H[1], a2 = Constants.SHA_H[2], a3 = Constants.SHA_H[3], a4 = Constants.SHA_H[4];
@@ -0,0 +1,17 @@
package de.caydenno1.xacrypto.hash.sha224;
import java.nio.charset.StandardCharsets;
import static de.caydenno1.xacrypto.hash.sha224.SHA224.digest;
public class Digest {
public static String digestHex(String text) {
byte[] hash = digest(text.getBytes(StandardCharsets.UTF_8));
StringBuilder builder = new StringBuilder(hash.length * 2);
for (byte b : hash) builder.append(String.format("%02x", b & 0xFF));
return builder.toString();
}
}
@@ -0,0 +1,29 @@
package de.caydenno1.xacrypto.hash.sha224;
import static de.caydenno1.xacrypto.hash.ROT.ROTR;
public class Helpers {
public static int ch(int x, int y, int z) {
return (x & y) ^ (~x & z);
}
public static int maj(int x, int y, int z) {
return (x & y) ^ (x & z) ^ (y & z);
}
public static int bigSigma0(int x) {
return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22);
}
public static int bigSigma1(int x) {
return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25);
}
public static int smallSigma0(int x) {
return ROTR(x, 7) ^ ROTR(x, 18) ^ (x >>> 3);
}
public static int smallSigma1(int x) {
return ROTR(x, 17) ^ ROTR(x, 19) ^ (x >>> 10);
}
}
@@ -0,0 +1,86 @@
package de.caydenno1.xacrypto.hash.sha224;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.ch;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.maj;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.bigSigma0;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.bigSigma1;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.smallSigma0;
import static de.caydenno1.xacrypto.hash.sha224.Helpers.smallSigma1;
import static de.caydenno1.xacrypto.misc.Constants.SHA224_H0;
import static de.caydenno1.xacrypto.misc.Constants.SHA224_K;
public class SHA224 {
public static byte[] digest(byte[] message) {
long bl = ((long) message.length) * 8L;
int paddingLength = 64 - (int) ((message.length + 9) % 64);
if (paddingLength == 64) paddingLength = 0;
byte[] pd = new byte[message.length + 1 + paddingLength + 8];
System.arraycopy(message, 0, pd, 0, message.length);
pd[message.length] = (byte) 0x80;
for (int i = 0 ; i < 8 ; i++) pd[pd.length - 1 - i] = (byte) (bl >>> (8 * i));
int[] h = SHA224_H0.clone();
int[] w = new int[64];
for (int off = 0 ; off < pd.length ; off += 64) {
for (int i = 0 ; i < 16 ; i++) {
int pos = off + i * 4;
w[i] = ((pd[pos] & 0xff) << 24) |
((pd[pos + 1] & 0xff) << 16) |
((pd[pos + 2] & 0xff) << 8) |
(pd[pos + 3] & 0xff);
}
for (int i = 16 ; i < 64 ; i++) {
w[i] = smallSigma1(w[i - 2]) +
w[i - 7] +
smallSigma0(w[i - 15]) +
w[i - 16];
}
int ha = h[0];
int hb = h[1];
int hc = h[2];
int hd = h[3];
int he = h[4];
int hf = h[5];
int hg = h[6];
int hh = h[7];
for (int i = 0 ; i < 64 ; i++) {
int t1 = hh + bigSigma1(he) + ch(he, hf, hg) + SHA224_K[i] + w[i];
int t2 = bigSigma0(ha) + maj(ha, hb, hc);
hh = hg;
hg = hf;
hf = he;
he = hd + t1;
hd = hc;
hc = hb;
hb = ha;
ha = t1 + t2;
}
h[0] += ha;
h[1] += hb;
h[2] += hc;
h[3] += hd;
h[4] += he;
h[5] += hf;
h[6] += hg;
h[7] += hh;
}
byte[] res = new byte[28];
for (int i = 0 ; i < 7 ; i++) for (int j = 0; j < 4; j++) res[i * 4 + j] = (byte) (h[i] >>> (24 - j * 8));
return res;
}
}
@@ -0,0 +1,117 @@
package de.caydenno1.xacrypto.hash.sha384;
import java.util.Arrays;
import static de.caydenno1.xacrypto.misc.Constants.SHA384_H0;
import static de.caydenno1.xacrypto.misc.Constants.SHA384_K;
import static de.caydenno1.xacrypto.hash.ROT.ROTR64;
import static de.caydenno1.xacrypto.hash.sha256.Hex.Byte2Hex;
public class SHA384 {
// digest
// pad
public static byte[] digest(byte[] mesg) {
long[] h = Arrays.copyOf(SHA384_H0, SHA384_H0.length);
byte[] pd = pad(mesg);
int c = pd.length / 128;
long[] w = new long[80];
for (int blk = 0 ; blk < c ; blk++) {
int base = blk * 128;
for (int t = 0 ; t < 16 ; t++) w[t] = BYTE2LONG(pd, base + t * 8);
for (int t = 16 ; t < 80 ; t ++) {
long s0 = ROTR64(w[t - 15], 1)
^ ROTR64(w[t - 15], 8)
^ (w[t - 15] >>> 7);
long s1 = ROTR64(w[t - 2], 19)
^ ROTR64(w[t - 2], 61)
^ w[t - 2] >>> 6;
w[t] = w[t - 16] + s0 + w[t - 7] + s1;
}
// a = h[0]
// b = h[1]
// c = h[2]
// d = h[3]
// e = h[4]
// f = h[5]
// g = h[6]
// h = h[7]
long[] h0 = Arrays.copyOf(h, h.length);
for (int t = 0 ; t < 80 ; t++) {
long S1 = ROTR64(h[4], 14)
^ ROTR64(h[4], 18)
^ ROTR64(h[4], 41);
long ch = (h[4] & h[5]) ^ (~h[4] & h[6]);
long _0 = h[7] + S1 + ch + SHA384_K[t] + w[t];
long S0 = ROTR64(h[0], 28)
^ ROTR64(h[0], 34)
^ ROTR64(h[0], 39);
long maj = (h[0] & h[1]) ^ (h[0] & h[2]) ^ (h[1] & h[2]);
long _1 = S0 + maj;
h[7] = h[6];
h[6] = h[5];
h[5] = h[4];
h[4] = h[3] + _0;
h[3] = h[2];
h[2] = h[1];
h[1] = h[0];
h[0] = _0 + _1;
}
for (int i = 0 ; i < 8 ; i++) h[i] += h0[i];
}
byte[] res = new byte[48];
for (int i = 0 ; i < 6 ; i++) LONG2BYTE(h[i], res, i*8);
return res;
};
public static byte[] pad(byte[] mesg) {
long MLB = (long) mesg.length * 8L;
int mod = mesg.length % 128;
int pLen;
if (mod < 112) {
pLen = 112 - mod;
} else {
pLen = 240 - mod;
}
byte[] pd = new byte[mesg.length + pLen + 16];
System.arraycopy(mesg, 0, pd, 0, mesg.length);
pd[mesg.length] = (byte) 0x80;
int off = pd.length - 16;
LONG2BYTE(0L, pd, off);
LONG2BYTE(MLB, pd, off + 8);
return pd;
}
private static long BYTE2LONG(byte[] bytes, int off) {
long res = 0;
for (int i = 0 ; i < 8 ; i++) res = (res << 8) | (bytes[off + i] & 0xFFL);
return res;
}
private static void LONG2BYTE(long val, byte[] bytes, int off) {
for (int i = 7 ; i >= 0 ; i--) {
bytes[off + i] = (byte) (val & 0xFF);
val >>>= 8;
}
}
}
@@ -0,0 +1,95 @@
package de.caydenno1.xacrypto.hash.sha512;
import java.util.Arrays;
import static de.caydenno1.xacrypto.hash.ROT.ROTR64;
import static de.caydenno1.xacrypto.misc.Constants.SHA512_H0;
import static de.caydenno1.xacrypto.misc.Constants.SHA512_K;
public class SHA512 {
public static byte[] digest(byte[] mesg) {
long bitLen = (long) mesg.length * 8L;
int mod = mesg.length % 128;
int pLen;
if (mod < 112) {
pLen = 112 - mod;
} else {
pLen = 240 - mod;
}
byte[] pd = new byte[mesg.length + pLen + 16];
System.arraycopy(mesg, 0, pd, 0, mesg.length);
pd[mesg.length] = (byte) 0x80;
int off = pd.length - 16;
LONG2BYTE(0L, pd, off);
LONG2BYTE(bitLen, pd, off + 8);
long[] H = Arrays.copyOf(SHA512_H0, 8);
long[] W = new long[80];
for (int blk = 0; blk < pd.length / 128; blk++) {
int base = blk * 128;
long[] pH = Arrays.copyOf(H, 8);
for (int t = 0; t < 16; t++) W[t] = BYTE2LONG(pd, base + t * 8);
for (int t = 16; t < 80; t++) {
long s0 = ROTR64(W[t - 15], 1) ^ ROTR64(W[t - 15], 8) ^ (W[t - 15] >>> 7);
long s1 = ROTR64(W[t - 2], 19) ^ ROTR64(W[t - 2], 61) ^ (W[t - 2] >>> 6);
W[t] = W[t - 16] + s0 + W[t - 7] + s1;
}
for (int t = 0; t < 80; t++) {
long S1 = ROTR64(H[4], 14) ^ ROTR64(H[4], 18) ^ ROTR64(H[4], 41);
long ch = (H[4] & H[5]) ^ (~H[4] & H[6]);
long T1 = H[7] + S1 + ch + SHA512_K[t] + W[t];
long S0 = ROTR64(H[0], 28) ^ ROTR64(H[0], 34) ^ ROTR64(H[0], 39);
long maj = (H[0] & H[1]) ^ (H[0] & H[2]) ^ (H[1] & H[2]);
long T2 = S0 + maj;
H[7] = H[6];
H[6] = H[5];
H[5] = H[4];
H[4] = H[3] + T1;
H[3] = H[2];
H[2] = H[1];
H[1] = H[0];
H[0] = T1 + T2;
}
for (int i = 0; i < 8; i++) H[i] += pH[i];
}
byte[] o = new byte[64];
for (int i = 0; i < 8; i++) LONG2BYTE(H[i], o, i * 8);
return o;
}
private static long BYTE2LONG(byte[] bytes, int off) {
long res = 0;
for (int i = 0; i < 8; i++) res = (res << 8) | (bytes[off + i] & 0xFFL);
return res;
}
private static void LONG2BYTE(long val, byte[] bytes, int off) {
for (int i = 7; i >= 0; i--) {
bytes[off + i] = (byte) (val & 0xFF);
val >>>= 8;
}
}
public static String BYTE2STR(byte[] data) {
StringBuilder sb = new StringBuilder(data.length * 2);
for (byte b : data) {
sb.append(Character.forDigit((b >>> 4) & 0xF, 16));
sb.append(Character.forDigit(b & 0xF, 16));
}
return sb.toString();
}
}
Binary file not shown.
@@ -17,7 +17,7 @@ public class XACryptoException extends Exception {
} }
public XACryptoException(String res, int iid) { public XACryptoException(String res, int iid) {
super(res); super(res);
this.id = iid; this.id = iid & 0xFF;
} }
public XACryptoException(String[] pnts, byte id){ public XACryptoException(String[] pnts, byte id){
super(String.join("|", pnts)); super(String.join("|", pnts));
@@ -10,13 +10,6 @@ public class isNull {
return Objects.isNull(v) || v == null || v == alt; return Objects.isNull(v) || v == null || v == alt;
} }
public static boolean isValidText(String s) { public static boolean isValidText(String s) {
if (s.isBlank() || s.trim().isEmpty()) return false; return !isNull(s) && !s.isBlank();
switch (s) {
case "":
case null:
return false;
default:
return true;
}
}; };
} }
@@ -0,0 +1,68 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless;
import de.caydenno1.xacrypto.zekerrijndael.GCM.AES;
public class AESECB implements ECB {
private final AES engine;
public AESECB(byte[] key) throws XACryptoException {
int bits = switch (key.length){
case 16 -> 128;
case 24 -> 192;
case 32 -> 256;
default -> throw new XACryptoException("aes keys must be 16, 24, or 32 in length.");
};
this.engine = new AES(key, bits);
}
public byte[] encrypt(byte[] pln) throws XACryptoException {
int pLen = 16 - (pln.length % 16);
byte[] pData = new byte[pln.length + pLen];
System.arraycopy(pln, 0, pData, 0, pln.length);
for (int i = pln.length ; i < pData.length ; i++) pData[i] = (byte)pLen;
byte[] cip = new byte[pData.length];
byte[] in = new byte[16];
for (int i = 0 ; i < pData.length ; i += 16) {
System.arraycopy(pData, i, in, 0, 16);
byte[] o = engine.encryptBlock(in);
System.arraycopy(o, 0, cip, i, 16);
}
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length % 16 != 0) throw new XACryptoException("ciptext length must be of a 16-byte size :[");
byte[] Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_ = new byte[cip.length];
byte[] in = new byte[16];
for (int i = 0 ; i < cip.length ; i += 16) {
System.arraycopy(cip, i, in, 0, 16);
byte[] o = engine.decryptBlock(in);
System.arraycopy(o, 0, Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_, i, 16);
}
int pLen = Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_[Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_.length - 1] & 0xFF;
if (pLen < 1 || pLen > 16) throw new XACryptoException("padding must be 1-16 exclusive in length", (int) pLen);
for (int i = Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_.length - pLen; i < Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_.length; i++) {
if (((Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_[i] & 0xFF) != pLen)) {
throw new XACryptoException("something up with yo padding.. :(");
}
}
byte[] pln = new byte[Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_.length - pLen];
System.arraycopy(Microsoft_Copilot_is_your_companion_to_inform__entertain_and_inspire__Get_advice__feedback_and_straightforward_answers__Try_Copilot_now_, 0, pln, 0, pln.length);
return pln;
}
}
@@ -1,14 +1,10 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers; package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB;
import de.caydenno1.xacrypto.zekerrijndael.Global.Aria; import de.caydenno1.xacrypto.zekerrijndael.Global.Aria;
interface AriaCipher { public class AriaECB implements ECB {
public byte[] encrypt(byte[] pln) throws XACryptoException;
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
public class AriaECB implements AriaCipher {
private final Aria engine; private final Aria engine;
public AriaECB(byte[] key) throws XACryptoException { public AriaECB(byte[] key) throws XACryptoException {
@@ -2,13 +2,9 @@ package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.Blowfish; import de.caydenno1.xacrypto.zekerrijndael.ECB.Blowfish;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless;
interface BlowfishCipher { public class BlowfishECB implements ECBExceptionless {
public byte[] encrypt(byte[] pln);
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
public class BlowfishECB implements BlowfishCipher {
private final Blowfish engine; private final Blowfish engine;
public BlowfishECB(byte[] key) throws XACryptoException { public BlowfishECB(byte[] key) throws XACryptoException {
@@ -0,0 +1,49 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless;
import de.caydenno1.xacrypto.zekerrijndael.Global.Camellia;
public class CamelliaECB implements ECBExceptionless {
private final Camellia engine;
public CamelliaECB(byte[] key) throws XACryptoException {
this.engine = new Camellia(key);
}
public byte[] encrypt(byte[] pln) {
int pLen = 16 - (pln.length % 16);
byte[] pData = new byte[pln.length + pLen];
System.arraycopy(pln, 0, pData, 0, pln.length);
for (int i = pln.length; i < pData.length; i++) {
pData[i] = (byte) pLen;
}
byte[] cip = new byte[pData.length];
for (int i = 0 ; i < pData.length ; i += 16) {
engine.encryptBlock(pData, i, cip, i);
}
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length % 16 != 0) throw new XACryptoException("something somewhere, for some reason, is broken. somthing with camelliaecb !",(int)cip.length);
byte[] He_s_from_British_Columbia = new byte[cip.length];
for (int i = 0 ; i < cip.length ; i += 16) {
engine.decryptBlock(cip, i, He_s_from_British_Columbia, i);
}
int pLen = He_s_from_British_Columbia[He_s_from_British_Columbia.length - 1] & 0xFF;
byte[] pln = new byte[He_s_from_British_Columbia.length - pLen];
System.arraycopy(He_s_from_British_Columbia, 0, pln, 0, pln.length);
return pln;
}
}
@@ -0,0 +1,101 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.*;
import static de.caydenno1.xacrypto.zekerrijndael.Global.LE32.*;
public class RC6ECB implements ECB {
private final int[] S;
// 20 rounds
public RC6ECB(byte[] key) throws XACryptoException {
if (key.length <= 0 || key.length > 255) throw new XACryptoException("keys must be 1-255 bytes inclusive :\\");
int c = Math.max(1, (key.length + 3) / 4);
int[] L = new int[c];
for (int i = 0 ; i < key.length ; i++) L[i / 4] |= (key[i] & 0xFF) << (8 * (i % 4));
S = new int[44 /* 2x 20 rounds = 40 rounds + 4 = 44. */];
S[0] = RC6_P;
for (int i = 1 ; i < S.length ; i++) S[i] = S[i - 1] + RC6_Q;
int A = 0, B = 0, i = 0, j = 0;
int v = 3 * Math.max(c, S.length);
for (int s = 0 ; s < v ; s++) {
A = S[i] = Integer.rotateLeft(S[i] + A + B, 3);
B = L[j] = Integer.rotateLeft(L[j] + A + B, A + B);
i = (i + 1)%S.length;
j = (j + 1)%c;
}
}
private void encryptBlock(byte[] in, int inOff, byte[] out, int outOff) {
int[] data = new int[4];
for (int i = 0; i < 4; i++) data[i] = read32LE(in, inOff + (i * 4));
data[1] += S[0];
data[3] += S[1];
for (int i = 1 ; i <= 20 ; i++) {
int t = Integer.rotateLeft(data[1] * (2 * data[1] + 1), 5);
int u = Integer.rotateLeft(data[3] * (2 * data[3] + 1), 5);
data[0] = Integer.rotateLeft(data[0] ^ t, u) + S[2 * i];
data[2] = Integer.rotateLeft(data[2] ^ u, t) + S[2 * i + 1];
int _0 = data[0]; data[0] = data[1]; data[1] = data[2]; data[2] = data[3]; data[3] = _0;
}
data[0] += S[42];
data[2] += S[43];
for (int i = 0; i < 4; i++) write32LE(data[i], out, outOff + (i * 4));
};
private void decryptBlock(byte[] in, int inOff, byte[] out, int outOff) {
int[] data = new int[4];
for (int i = 0; i < 4; i++) data[i] = read32LE(in, inOff + (i * 4));
data[2] -= S[43];
data[0] -= S[42];
for (int i = 20 ; i >= 1 ; i--) {
int _0 = data[3]; data[2] = data[1]; data[1] = data[0]; data[0] = _0;
int u = Integer.rotateLeft(data[3] * (2 * data[3] + 1), 5);
int t = Integer.rotateLeft(data[1] * (2 * data[1] + 1), 5);
data[2] = Integer.rotateRight(data[2] - S[2 * i + 1], t) ^ u;
data[0] = Integer.rotateRight(data[0] - S[2 * i], u) ^ t;
}
data[3] -= S[1];
data[1] -= S[0];
for (int i = 0; i < 4; i++) write32LE(data[i], out, outOff + (i * 4));
}
public byte[] encrypt(byte[] pln) throws XACryptoException {
int pLen = 16 - (pln.length % 16);
byte[] pData = new byte[pln.length + pLen];
System.arraycopy(pln, 0, pData, 0, pln.length);
for (int i = pln.length ; i < pData.length ; i++) pData[i] = (byte) pLen;
byte[] cip = new byte[pData.length];
for (int i = 0 ; i < pData.length ; i += 16) encryptBlock(pData, i, cip, i);
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length % 16 != 0) throw new XACryptoException("ciptext length is not a multiple of 16");
byte[] de = new byte[cip.length];
for (int i = 0 ; i < cip.length ; i += 16) decryptBlock(cip, i, de, i);
int pLen = de[de.length - 1] & 0xFF;
byte[] pln = new byte[de.length - pLen];
System.arraycopy(de, 0, pln, 0, pln.length);
return pln;
}
}
@@ -1,18 +1,14 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers; package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_FK; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_FK;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_CK; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_CK;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_SBOX; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SM4_SBOX;
import static de.caydenno1.xacrypto.hash.ROT.ROTL; import static de.caydenno1.xacrypto.hash.ROT.ROTL;
interface SM4Cipher { public class SM4ECB implements ECBExceptionless {
byte[] encrypt(byte[] pln);
byte[] decrypt(byte[] cip) throws XACryptoException;
}
public class SM4ECB implements SM4Cipher {
public final int[] encRK = new int[32]; public final int[] encRK = new int[32];
public final int[] decRK = new int[32]; public final int[] decRK = new int[32];
@@ -0,0 +1,56 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB;
import de.caydenno1.xacrypto.zekerrijndael.Global.Twofish;
public class TwofishECB implements ECB {
private final Twofish engine;
public TwofishECB(byte[] key) throws XACryptoException {
this.engine = new Twofish(key);
}
public byte[] encrypt(byte[] pln) throws XACryptoException {
int pLen = 16 - (pln.length % 16);
byte[] pData = new byte[pln.length + pLen];
System.arraycopy(pln, 0, pData, 0, pln.length);
for (int i = pln.length ; i < pData.length ; i++) pData[i] = (byte)pLen;
byte[] cip = new byte[pData.length];
byte[] in = new byte[16];
for (int i = 0 ; i < pData.length ; i += 16) {
System.arraycopy(pData, i, in, 0, 16);
byte[] o = engine.encryptBlock(in);
System.arraycopy(o, 0, cip, i, 16);
}
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length % 16 != 0) throw new XACryptoException("length of ciptext must be 16-byte (multiple of 16)");
byte[] Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___ = new byte[cip.length];
byte[] l = new byte[16];
for (int i = 0 ; i < cip.length ; i += 16) {
System.arraycopy(cip, i, l, 0, 16);
byte[] o = engine.decryptBlock(l);
System.arraycopy(o, 0, Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___, i, 16);
}
int pLen = Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___[Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___.length - 1] & 0xFF;
byte[] pln = new byte[Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___.length - pLen];
System.arraycopy(Less_Stress__More_Travel___Find___Compare_Options_and_You_Can_Save_Big_on_Expedia_com__Get___, 0, pln, 0, pln.length);
return pln;
}
}
@@ -0,0 +1,9 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces;
import de.caydenno1.xacrypto.misc.XACryptoException;
public interface ECB {
public byte[] encrypt(byte[] pln) throws XACryptoException;
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
@@ -0,0 +1,8 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces;
import de.caydenno1.xacrypto.misc.XACryptoException;
public interface ECBExceptionless extends ECB {
public byte[] encrypt(byte[] pln);
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
@@ -1,22 +1,78 @@
package de.caydenno1.xacrypto.zekerrijndael; package de.caydenno1.xacrypto.zekerrijndael;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.AriaECB; import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.*;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.BlowfishECB; import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB;
import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.SM4ECB; import de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless;
import de.caydenno1.xacrypto.zekerrijndael.GCM.AES; import de.caydenno1.xacrypto.zekerrijndael.GCM.AES;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM; import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM;
import de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers.*; import de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers.*;
import java.lang.reflect.InvocationTargetException; import de.caydenno1.xacrypto.zekerrijndael.Global.Aria;
import de.caydenno1.xacrypto.zekerrijndael.Global.Camellia;
public class Factories { public class Factories {
public static GCM AES128(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new GCM(new AES(key, 128)); } public static class GCM {
public static GCM SM4GCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new GCM(new SM4GCM(key));} public static de.caydenno1.xacrypto.zekerrijndael.GCM.GCM AES128(byte[] key) throws XACryptoException { return new de.caydenno1.xacrypto.zekerrijndael.GCM.GCM(new AES(key, 128)); }
public static GCM Camellia(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new GCM(new Camellia(key));}
public static GCM AESGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new GCM(new AESGCM());} public static de.caydenno1.xacrypto.zekerrijndael.GCM.GCM SM4GCM(byte[] key) throws XACryptoException { return new de.caydenno1.xacrypto.zekerrijndael.GCM.GCM(new SM4GCM(key)); }
public static ARIAGCM ARIAGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new ARIAGCM(key); }
public static GCM SerpentGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { return new SerpentGCM(key); } public static de.caydenno1.xacrypto.zekerrijndael.GCM.GCM Camellia(byte[] key) throws XACryptoException { return new de.caydenno1.xacrypto.zekerrijndael.GCM.GCM(new Camellia(key)); }
public static BlowfishECB BlowfishECB(byte[] key) throws XACryptoException { return new BlowfishECB(key); }
public static AriaECB AriaECB(byte[] key) throws XACryptoException { return new AriaECB(key); } public static de.caydenno1.xacrypto.zekerrijndael.GCM.GCM ARIAGCM(byte[] key) throws XACryptoException { return new de.caydenno1.xacrypto.zekerrijndael.GCM.GCM(new Aria(true, key)); }
public static SM4ECB SM4ECB(byte[] key) throws XACryptoException { return new SM4ECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.GCM.GCM SerpentGCM(byte[] key) throws XACryptoException { return new SerpentGCM(key); }
}
private static volatile boolean ecbOptIn = false;
/**
* Enables the use of ECB mode.
*
* <p><strong>Warning:</strong> ECB mode is insecure for
* almost all applications because identical plaintext blocks
* produce identical ciphertext blocks, leaking data patterns.
*
* <p>This method exists solely for backwards compatibility.
* Prefer {@link Factories.GCM} or another secure encryption mode.
* The contributor that has written this wishes to remain anonymous.
*/
public static void allowInsecureECB() {
ecbOptIn = true;
}
private static void checkECBenabled() throws XACryptoException {
if (!ecbOptIn) {
throw new XACryptoException(
"ECB mode is not secure because it can leak data patterns. Call Factories.allowInsecureECB() before using ECB."
);
}
}
/**
* Provides ECB mode cipher factories.
*
* <p><strong>Warning:</strong> ECB mode is insecure because identical
* plaintext blocks produce identical ciphertext blocks, leaking data patterns.
*
* <p>This class requires opt-in using
* {@link Factories#allowInsecureECB()} and exists only for backwards compatibility.
*
* @deprecated Use GCM or another secure encryption mode instead.
*/
@Deprecated
public static class ECB {
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless Blowfish(byte[] key) throws XACryptoException { checkECBenabled(); return new BlowfishECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB Aria(byte[] key) throws XACryptoException { checkECBenabled(); return new AriaECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless SM4(byte[] key) throws XACryptoException { checkECBenabled(); return new SM4ECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB AES(byte[] key) throws XACryptoException { checkECBenabled(); return new AESECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB Twofish(byte[] key) throws XACryptoException { checkECBenabled(); return new TwofishECB(key); }
public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECB RC6ECB(byte[] key) throws XACryptoException { checkECBenabled(); return new RC6ECB(key); }
//public static de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers.interfaces.ECBExceptionless CamelliaECB(byte[] key) throws XACryptoException { return new CamelliaECB(key); }
}
} }
@@ -1,11 +1,10 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM; package de.caydenno1.xacrypto.zekerrijndael.GCM;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import static de.caydenno1.xacrypto.zekerrijndael.Global.Galois.*;
import java.util.Arrays; import java.util.Arrays;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.*; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.*;
@SuppressWarnings("unused")
public final class AES implements BlockCipher { public final class AES implements BlockCipher {
public final int bits; public final int bits;
public int kc; public int kc;
@@ -62,6 +61,64 @@ public final class AES implements BlockCipher {
return o; return o;
} }
public byte[] decryptBlock(byte[] input) throws XACryptoException {
int m = switch (bits) {
case 128 -> 10;
case 192 -> 12;
case 256 -> 14;
default -> throw new XACryptoException("only 128, 192 and 256 bit ciphers are supported atm. sorry :%");
};
byte[][] s = new byte[4][4];
for (int i = 0; i < 16; i++) s[i & 3][i >> 2] = input[i];
addRoundKey(s, m);
for (int r = m - 1 ; r > 0 ; r--) {
invShift(s);
invSub(s);
addRoundKey(s, r);
invMC(s);
}
invShift(s);
invSub(s);
addRoundKey(s, 0);
byte[] o = new byte[16];
for (int i = 0 ; i < 16 ; i++) o[i] = s[i & 3][i >> 2];
return o;
}
private static void invSub(byte[][] s) {
for (int _0 = 0 ; _0 < 4 ; _0++) for (int _1 = 0 ; _1 < 4 ; _1++) s[_0][_1] = (byte) ARIA_XB1 /*for some reason ARIA's Inverse 1 Box is the same as AES's Inverse SBOX?*/ [s[_0][_1] & 0xFF];
}
private static void invShift(byte[][] s) {
byte t;
for (int _0 = 1 ; _0 < 4 ; _0++) {
byte[] _1 = new byte[4];
for (int _2 = 0 ; _2 < 4 ; _2++) _1[(_2 + _0) % 4] = s[_0][_2];
for (int _2 = 0 ; _2 < 4 ; _2++) s[_0][_2] = _1[_2];
}
}
private static void invMC(byte[][] s) {
for (int _0 = 0; _0 < 4; _0++) {
byte a0 = s[0][_0]; byte a1 = s[1][_0]; byte a2 = s[2][_0]; byte a3 = s[3][_0];
s[0][_0] = (byte)(gm14(a0) ^ gm11(a1) ^ gm13(a2) ^ gm9(a3));
s[1][_0] = (byte)(gm9(a0) ^ gm14(a1) ^ gm11(a2) ^ gm13(a3));
s[2][_0] = (byte)(gm13(a0) ^ gm9(a1) ^ gm14(a2) ^ gm11(a3));
s[3][_0] = (byte)(gm11(a0) ^ gm13(a1) ^ gm9(a2) ^ gm14(a3));
}
}
// private void sub(byte[][] s) { // private void sub(byte[][] s) {
// for (int c = 0; c < 4; c++) { // for (int c = 0; c < 4; c++) {
// for (int r = 0; r < 4; r++) { // for (int r = 0; r < 4; r++) {
@@ -116,14 +173,7 @@ public final class AES implements BlockCipher {
} }
} }
private static byte gm2(byte b) {
int x = b & 0xFF;
return (byte)((((x << 1) & 0xFF) ^ ((x & 0x80) != 0 ? 0x1b : 0)));
}
private static byte gm3(byte b) {
return (byte)(gm2(b) ^ b);
}
private void addRoundKey(byte[][] s, int round) { private void addRoundKey(byte[][] s, int round) {
for (int c = 0; c < 4; c++) { for (int c = 0; c < 4; c++) {
@@ -1,28 +1,26 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM; package de.caydenno1.xacrypto.zekerrijndael.GCM;
import de.caydenno1.xacrypto.misc.ToM; import de.caydenno1.xacrypto.misc.ToM;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.misc.isNull; import de.caydenno1.xacrypto.misc.isNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
public class GCM { public class GCM {
private final Object cip; private static final Logger log = LoggerFactory.getLogger(GCM.class);
private final BlockCipher cip;
private final GHASH gh; private final GHASH gh;
private final Method encryptor;
public GCM(Object cip) throws XACryptoException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { public GCM(BlockCipher cip) throws XACryptoException {
this.cip = cip; this.cip = cip;
this.encryptor = cip.getClass().getMethod("encryptBlock", byte[].class); byte[] H = cip.encryptBlock(new byte[16]);
byte[] H = (byte[]) this.encryptor.invoke(cip, (Object) new byte[16]);
this.gh = new GHASH(H); this.gh = new GHASH(H);
} }
public Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException, InvocationTargetException, IllegalAccessException { public Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException {
if (iv.length <= 0) throw new XACryptoException("iv does not have data or is corrupted :["); if (iv.length <= 0) throw new XACryptoException("iv does not have data or is corrupted :[");
if (pln == null) pln = new byte[0]; if (pln == null) pln = new byte[0];
if (aad == null) aad = new byte[0]; if (aad == null) aad = new byte[0];
@@ -38,23 +36,23 @@ public class GCM {
return new Result(packaged,tag); return new Result(packaged,tag);
} }
public byte[] decrypt(Result res, byte[] aad) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad) throws XACryptoException {
return dec(res, aad, 12, false); return dec(res, aad, 12, false);
} }
public byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException {
return dec(res, aad, 12, Objects.equals(optflag, "-override")); return dec(res, aad, 12, Objects.equals(optflag, "-override"));
} }
public byte[] decrypt(Result res, byte[] aad, int ivLen) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad, int ivLen) throws XACryptoException {
return dec(res, aad, ivLen, false); return dec(res, aad, ivLen, false);
} }
public byte[] decrypt(Result res, byte[] aad, int ivLen, String optflag) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad, int ivLen, String optflag) throws XACryptoException {
return dec(res, aad, ivLen, Objects.equals(optflag, "-override")); return dec(res, aad, ivLen, Objects.equals(optflag, "-override"));
} }
private byte[] dec(Result res, byte[] aad, int ivLen, boolean override) throws XACryptoException, InvocationTargetException, IllegalAccessException { private byte[] dec(Result res, byte[] aad, int ivLen, boolean override) throws XACryptoException {
if (res.cip().length < 12) throw new XACryptoException("ciptext min len is 12 char"); if (res.cip().length < 12) throw new XACryptoException("ciptext min len is 12 char");
if (isNull.isNull(aad)) aad = new byte[0]; if (isNull.isNull(aad)) aad = new byte[0];
@@ -69,7 +67,7 @@ public class GCM {
if (!corr && !override) { if (!corr && !override) {
throw new XACryptoException("GCM tag does not match. Use Flag -override to ignore this.",(byte)-1); throw new XACryptoException("GCM tag does not match. Use Flag -override to ignore this.",(byte)-1);
} else if (!corr) { } else if (!corr) {
System.out.println("GCM tag does not match. Overriding..."); log.warn("GCM tag does not match. Overriding...");
} }
return gctr(inc32(J0), ct); return gctr(inc32(J0), ct);
@@ -86,17 +84,17 @@ public class GCM {
} }
} }
private byte[] tag(byte[] aad, byte[] ct, byte[] J0) throws InvocationTargetException, IllegalAccessException { private byte[] tag(byte[] aad, byte[] ct, byte[] J0) throws XACryptoException {
byte[] S = gh.compute(aad, ct); byte[] S = gh.compute(aad, ct);
byte[] EJ0 = (byte[]) this.encryptor.invoke(J0); byte[] EJ0 = cip.encryptBlock(J0);
for (int i = 0; i < 16; i++) S[i] ^= EJ0[i]; for (int i = 0; i < 16; i++) S[i] ^= EJ0[i];
return S; return S;
} }
private byte[] gctr(byte[] icb, byte[] in) throws InvocationTargetException, IllegalAccessException { private byte[] gctr(byte[] icb, byte[] in) throws XACryptoException {
byte[] o = new byte[in.length]; byte[] o = new byte[in.length];
byte[] cnt = Arrays.copyOf(icb, 16); byte[] cnt = Arrays.copyOf(icb, 16);
for (int i = 0 ; i < in.length ; i += 16){ for (int i = 0 ; i < in.length ; i += 16){
byte[] ks = (byte[]) this.encryptor.invoke(cnt); byte[] ks = cip.encryptBlock(cnt);
int len = Math.min(16, in.length -i); int len = Math.min(16, in.length -i);
for (int j = 0; j < len; j++) o[i + j] = (byte)(in[i + j] ^ ks[j]); for (int j = 0; j < len; j++) o[i + j] = (byte)(in[i + j] ^ ks[j]);
if (i+16<in.length) cnt = inc32(cnt); if (i+16<in.length) cnt = inc32(cnt);
@@ -14,24 +14,23 @@ public class GHASH {
} }
public byte[] compute(byte[] aad, byte[] cip){ public byte[] compute(byte[] aad, byte[] cip){
byte[] Y = new byte[16]; byte[] Y = proc(new byte[16], aad);
Y = proc(Y, aad);
Y = proc(Y, cip); Y = proc(Y, cip);
byte[] lenBlock = buildLenBlock( byte[] lenBlock = buildLenBlock(
aad.length * 8L, aad.length * 8L,
cip.length * 8L cip.length * 8L
); );
Y = xor(Y, lenBlock); xor(Y, lenBlock);
Y = multi(Y,H); Y = multi(Y,H);
return Y; return Y;
} }
private byte[] proc(byte[] Y, byte[] in) { private byte[] proc(byte[] Y, byte[] in) {
byte[] bloc = new byte[16];
for (int off = 0; off < in.length; off+=16){ for (int off = 0; off < in.length; off+=16){
byte[] bloc = new byte[16];
int len = Math.min(16, in.length - off); int len = Math.min(16, in.length - off);
System.arraycopy(in, off, bloc, 0, len); System.arraycopy(in, off, bloc, 0, len);
Y = xor(Y, bloc); xor(Y, bloc);
Y = multi(Y, H); Y = multi(Y, H);
} }
return Y; return Y;
@@ -43,13 +42,13 @@ public class GHASH {
int byindex = bit / 8; int byindex = bit / 8;
int biindex = 7 - (bit%8); int biindex = 7 - (bit%8);
if (((X[byindex] >> biindex) & 1) == 1) Z = xor(Z,V); if (((X[byindex] >> biindex) & 1) == 1) xor(Z,V);
boolean isLSB1 = (V[15] & 1) != 0; boolean isLSB1 = (V[15] & 1) != 0;
RS(V); RS(V);
if (isLSB1) V = xor(V,UnchangingData.R); if (isLSB1) xor(V,UnchangingData.R);
} }
return Z; return Z;
} }
@@ -64,7 +63,6 @@ public class GHASH {
} }
} }
public byte[] compNonce(byte[] H, byte[] nonce){ public byte[] compNonce(byte[] H, byte[] nonce){
byte[] Y = new byte[16];
byte[] blk = new byte[16]; byte[] blk = new byte[16];
int len = nonce.length; int len = nonce.length;
@@ -90,9 +88,7 @@ public class GHASH {
blk[i] = (byte) ((bL >>> (8 * (15-i))) & 0xFF); blk[i] = (byte) ((bL >>> (8 * (15-i))) & 0xFF);
} }
Y = xor(Y,blk); return multi(blk, H);
Y = multi(Y, H);
return Y;
} }
private byte[] buildLenBlock(long aad, long cipb) { private byte[] buildLenBlock(long aad, long cipb) {
ByteBuffer buf = ByteBuffer.allocate(16); ByteBuffer buf = ByteBuffer.allocate(16);
@@ -103,8 +99,7 @@ public class GHASH {
return buf.array(); return buf.array();
} }
public byte[] xor(byte[] a, byte[] b){ public byte[] xor(byte[] a, byte[] b){
byte[] res = new byte[16]; for (int i = 0 ; i < 16 ; i++) a[i] ^= b[i];
for (int i = 0 ; i < 16 ; i++) res[i] = (byte) (a[i] ^ b[i]); return a;
return res;
} }
} }
@@ -4,6 +4,8 @@ import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GHASH; import de.caydenno1.xacrypto.zekerrijndael.GCM.GHASH;
import de.caydenno1.xacrypto.zekerrijndael.GCM.AES; import de.caydenno1.xacrypto.zekerrijndael.GCM.AES;
import de.caydenno1.xacrypto.zekerrijndael.GCM.Result; import de.caydenno1.xacrypto.zekerrijndael.GCM.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects; import java.util.Objects;
@@ -16,18 +18,17 @@ interface AESCipher {
} }
public class AESGCM implements AESCipher { public class AESGCM implements AESCipher {
public Result encryptBlock(byte[] pln, byte[] key, byte[] nonce, byte[] aad) throws XACryptoException { private static final Logger log = LoggerFactory.getLogger(AESGCM.class);
System.out.println("WARNING! AESGCM may not be fully functional and partially broken. I am unsure if it fully works or not.");
@SuppressWarnings("DuplicatedCode")
byte[] zbyte = new byte[16];
byte[] J0 = new byte[16];
public Result encryptBlock(byte[] pln, byte[] key, byte[] nonce, byte[] aad) throws XACryptoException {
log.warn("AESGCM may not be fully functional and partially broken. I am unsure if it fully works or not.");
AES aes = new AES(key, getKeySize(key)); AES aes = new AES(key, getKeySize(key));
@SuppressWarnings("DuplicatedCode") byte[] H = aes.encryptBlock(new byte[16]);
byte[] H = aes.encryptBlock(zbyte);
GHASH gh = new GHASH(H); GHASH gh = new GHASH(H);
byte[] J0;
if (nonce.length == 12) { if (nonce.length == 12) {
J0 = new byte[16];
System.arraycopy(nonce, 0, J0, 0, 12); System.arraycopy(nonce, 0, J0, 0, 12);
J0[15] = 1; J0[15] = 1;
} else { } else {
@@ -63,14 +64,13 @@ public class AESGCM implements AESCipher {
}; };
} }
private byte[] decBack(byte[] cip, byte[] key, byte[] nonce, byte[] aad, byte[] tag, boolean flag) throws XACryptoException { private byte[] decBack(byte[] cip, byte[] key, byte[] nonce, byte[] aad, byte[] tag, boolean flag) throws XACryptoException {
byte[] zbyte = new byte[16];
byte[] J0 = new byte[16];
@SuppressWarnings("DuplicatedCode")
AES aes = new AES(key, getKeySize(key)); AES aes = new AES(key, getKeySize(key));
byte[] H = aes.encryptBlock(zbyte); byte[] H = aes.encryptBlock(new byte[16]);
GHASH gh = new GHASH(H); GHASH gh = new GHASH(H);
byte[] J0;
if (nonce.length == 12) { if (nonce.length == 12) {
J0 = new byte[16];
System.arraycopy(nonce, 0, J0, 0, 12); System.arraycopy(nonce, 0, J0, 0, 12);
J0[15] = 1; J0[15] = 1;
} else { } else {
@@ -86,7 +86,7 @@ public class AESGCM implements AESCipher {
if (!ToM(tag, expectedTag) && !flag) { if (!ToM(tag, expectedTag) && !flag) {
throw new XACryptoException("Tag does not match. USE flag \"-override\" to ignore this."); throw new XACryptoException("Tag does not match. USE flag \"-override\" to ignore this.");
} else if (!ToM(tag,expectedTag) && flag) { } else if (!ToM(tag,expectedTag) && flag) {
System.out.println("Continuing in insecure mode."); log.warn("Continuing in insecure mode.");
} }
return aes.encryptCTR(cip, J0); return aes.encryptCTR(cip, J0);
@@ -5,12 +5,10 @@ import de.caydenno1.xacrypto.zekerrijndael.Global.Aria;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM; import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM;
import de.caydenno1.xacrypto.zekerrijndael.GCM.Result; import de.caydenno1.xacrypto.zekerrijndael.GCM.Result;
import java.lang.reflect.InvocationTargetException;
interface AriaCipher { interface AriaCipher {
Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException, InvocationTargetException, IllegalAccessException; Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException;
byte[] decrypt(Result res, byte[] aad) throws XACryptoException, InvocationTargetException, IllegalAccessException; byte[] decrypt(Result res, byte[] aad) throws XACryptoException;
byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException, InvocationTargetException, IllegalAccessException; byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException;
} }
public class ARIAGCM implements AriaCipher { public class ARIAGCM implements AriaCipher {
@@ -18,19 +16,19 @@ public class ARIAGCM implements AriaCipher {
// i basically wrote the entire thing in Aria.java already lol. just inheriting it here // i basically wrote the entire thing in Aria.java already lol. just inheriting it here
private final GCM engine; private final GCM engine;
public ARIAGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { public ARIAGCM(byte[] key) throws XACryptoException {
Aria aria = new Aria(true, key); Aria aria = new Aria(true, key);
this.engine = new GCM(aria); this.engine = new GCM(aria);
} }
public Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException, InvocationTargetException, IllegalAccessException { public Result encrypt(byte[] pln, byte[] aad, byte[] iv) throws XACryptoException {
return engine.encrypt(pln, aad,iv); return engine.encrypt(pln, aad,iv);
} }
public byte[] decrypt(Result res, byte[] aad) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad) throws XACryptoException {
return engine.decrypt(res, aad); return engine.decrypt(res, aad);
} }
public byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException, InvocationTargetException, IllegalAccessException { public byte[] decrypt(Result res, byte[] aad, String optflag) throws XACryptoException {
return engine.decrypt(res, aad, optflag); return engine.decrypt(res, aad, optflag);
} }
} }
@@ -0,0 +1,11 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM;
import de.caydenno1.xacrypto.zekerrijndael.Global.Camellia;
public class CamelliaGCM extends GCM {
public CamelliaGCM(byte[] key) throws XACryptoException {
super(new Camellia(key));
}
}
@@ -2,10 +2,8 @@ package de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM; import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM;
import de.caydenno1.xacrypto.zekerrijndael.GCM.Serpent; import de.caydenno1.xacrypto.zekerrijndael.Global.Serpent;
import java.lang.reflect.InvocationTargetException;
public class SerpentGCM extends GCM { public class SerpentGCM extends GCM {
public SerpentGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { super(new Serpent(key)); } public SerpentGCM(byte[] key) throws XACryptoException { super(new Serpent(key)); }
} }
@@ -2,12 +2,10 @@ package de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM; import de.caydenno1.xacrypto.zekerrijndael.GCM.GCM;
import de.caydenno1.xacrypto.zekerrijndael.GCM.Twofish; import de.caydenno1.xacrypto.zekerrijndael.Global.Twofish;
import java.lang.reflect.InvocationTargetException;
public class TwofishGCM extends GCM { public class TwofishGCM extends GCM {
public TwofishGCM(byte[] key) throws XACryptoException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { public TwofishGCM(byte[] key) throws XACryptoException {
super(new Twofish(key)); super(new Twofish(key));
} }
} }
@@ -1,9 +1,10 @@
package de.caydenno1.xacrypto.zekerrijndael.Global; package de.caydenno1.xacrypto.zekerrijndael.Global;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.BlockCipher;
import de.caydenno1.xacrypto.zekerrijndael.UnchangingData; import de.caydenno1.xacrypto.zekerrijndael.UnchangingData;
public class Aria { public class Aria implements BlockCipher {
// this is NOT a cipher, more or less and encryption type/method // this is NOT a cipher, more or less and encryption type/method
private final int round; private final int round;
private final byte[][] encRK; private final byte[][] encRK;
@@ -53,33 +54,29 @@ public class Aria {
System.arraycopy(encRK[0], 0, decRK[round], 0, 16); System.arraycopy(encRK[0], 0, decRK[round], 0, 16);
System.arraycopy(encRK[round], 0, decRK[0], 0, 16); System.arraycopy(encRK[round], 0, decRK[0], 0, 16);
byte[] _0 = new byte[16];
for (int i = 1 ; i < round ; i++){ for (int i = 1 ; i < round ; i++){
A(encRK[i], _0); A(encRK[i], decRK[round - i]);
System.arraycopy(_0, 0, decRK[round-i], 0, 16);
} }
} }
private void procRound(byte[] state, byte[][] rK){ private void procRound(byte[] state, byte[][] rK){
byte[] _0 = new byte[16];
for (int r = 0 ; r < round - 1 ; r++){ for (int r = 0 ; r < round - 1 ; r++){
AriaXOR(state,rK[r]); AriaXOR(state,rK[r]);
if (r % 2 == 0) { if (r % 2 == 0) {
SL1(state, _0); SL1(state, state);
} else { } else {
SL2(state, _0); SL2(state, state);
} }
A(_0, state); A(state, state);
} }
AriaXOR(state, rK[round-1]); AriaXOR(state, rK[round-1]);
if((round-1) % 2 == 0) { if((round-1) % 2 == 0) {
SL1(state, _0); SL1(state, state);
} else { } else {
SL2(state, _0); SL2(state, state);
} }
AriaXOR(_0, rK[round], state); AriaXOR(state, rK[round], state);
} }
private void AriaXOR(byte[] blk, byte[] key){ private void AriaXOR(byte[] blk, byte[] key){
@@ -110,17 +107,15 @@ public class Aria {
} }
// feistel odd // feistel odd
private void FO(byte[] i, byte[] ck, byte[] o) { private void FO(byte[] i, byte[] ck, byte[] o) {
byte[] _0 = new byte[16]; AriaXOR(i, ck, o);
AriaXOR(i, ck, _0); SL1(o, o);
SL1(_0, _0); A(o, o);
A(_0, o);
} }
//feistel even //feistel even
private void FE(byte[] i, byte[] ck, byte[] o) { private void FE(byte[] i, byte[] ck, byte[] o) {
byte[] _0 = new byte[16]; AriaXOR(i, ck, o);
AriaXOR(i, ck, _0); SL2(o, o);
SL2(_0, _0); A(o, o);
A(_0, o);
} }
private void SL1(byte[] i,byte[] o){ private void SL1(byte[] i,byte[] o){
@@ -176,62 +171,59 @@ public class Aria {
FO(W[2], CK[3], W[3]); FO(W[2], CK[3], W[3]);
AriaXOR(W[3], W[1], W[3]); AriaXOR(W[3], W[1], W[3]);
byte[] _0 = new byte[16]; SROTR128(W[1], 19, encRK[0]);
AriaXOR(W[0], encRK[0], encRK[0]);
SROTR128(W[1], 19, _0); SROTR128(W[2], 19, encRK[1]);
AriaXOR(W[0], _0, encRK[0]); AriaXOR(W[1], encRK[1], encRK[1]);
SROTR128(W[2], 19, _0); SROTR128(W[3], 19, encRK[2]);
AriaXOR(W[1], _0, encRK[1]); AriaXOR(W[2], encRK[2], encRK[2]);
SROTR128(W[3], 19, _0); SROTR128(W[0], 19, encRK[3]);
AriaXOR(W[2], _0, encRK[2]); AriaXOR(encRK[3], W[3], encRK[3]);
SROTR128(W[0], 19, _0); SROTR128(W[1], 31, encRK[4]);
AriaXOR(_0, W[3], encRK[3]); AriaXOR(W[0], encRK[4], encRK[4]);
SROTR128(W[1], 31, _0); SROTR128(W[2], 31, encRK[5]);
AriaXOR(W[0], _0, encRK[4]); AriaXOR(W[1], encRK[5], encRK[5]);
SROTR128(W[2], 31, _0); SROTR128(W[3], 31, encRK[6]);
AriaXOR(W[1], _0, encRK[5]); AriaXOR(W[2], encRK[6], encRK[6]);
SROTR128(W[3], 31, _0); SROTR128(W[0], 31, encRK[7]);
AriaXOR(W[2], _0, encRK[6]); AriaXOR(encRK[7], W[3], encRK[7]);
SROTR128(W[0], 31, _0); SROTR128(W[1], 128 - 61, encRK[8]);
AriaXOR(_0, W[3], encRK[7]); AriaXOR(W[0], encRK[8], encRK[8]);
SROTR128(W[1], 128 - 61, _0); SROTR128(W[2], 128 - 61, encRK[9]);
AriaXOR(W[0], _0, encRK[8]); AriaXOR(W[1], encRK[9], encRK[9]);
SROTR128(W[2], 128 - 61, _0); SROTR128(W[3], 128 - 61, encRK[10]);
AriaXOR(W[1], _0, encRK[9]); AriaXOR(W[2], encRK[10], encRK[10]);
SROTR128(W[3], 128 - 61, _0); SROTR128(W[0], 128 - 61, encRK[11]);
AriaXOR(W[2], _0, encRK[10]); AriaXOR(encRK[11], W[3], encRK[11]);
SROTR128(W[0], 128 - 61, _0); SROTR128(W[1], 128 - 31, encRK[12]);
AriaXOR(_0, W[3], encRK[11]); AriaXOR(W[0], encRK[12], encRK[12]);
SROTR128(W[1], 128 - 31, _0);
AriaXOR(W[0], _0, encRK[12]);
if (round >= 14) { if (round >= 14) {
SROTR128(W[2], 128 - 31, _0); SROTR128(W[2], 128 - 31, encRK[13]);
AriaXOR(W[1], _0, encRK[13]); AriaXOR(W[1], encRK[13], encRK[13]);
// ek15 = W2 ^ (W3 <<< 31) SROTR128(W[3], 128 - 31, encRK[14]);
SROTR128(W[3], 128 - 31, _0); AriaXOR(W[2], encRK[14], encRK[14]);
AriaXOR(W[2], _0, encRK[14]);
} }
if (round == 16) { if (round == 16) {
SROTR128(W[0], 128 - 31, _0); SROTR128(W[0], 128 - 31, encRK[15]);
AriaXOR(_0, W[3], encRK[15]); AriaXOR(encRK[15], W[3], encRK[15]);
SROTR128(W[1], 128 - 19, _0); SROTR128(W[1], 128 - 19, encRK[16]);
AriaXOR(W[0], _0, encRK[16]); AriaXOR(W[0], encRK[16], encRK[16]);
} }
} }
@@ -249,22 +241,24 @@ public class Aria {
} }
private void A(byte[] i, byte[] o) { private void A(byte[] i, byte[] o) {
// "diffusion layer" Matrix A byte[] _0 = o;
o[0] = (byte)(i[3] ^ i[4] ^ i[9] ^ i[14]); if (i == o) _0 = new byte[16];
o[1] = (byte)(i[2] ^ i[5] ^ i[8] ^ i[15]); _0[0] = (byte)(i[3] ^ i[4] ^ i[9] ^ i[14]);
o[2] = (byte)(i[1] ^ i[6] ^ i[11] ^ i[12]); _0[1] = (byte)(i[2] ^ i[5] ^ i[8] ^ i[15]);
o[3] = (byte)(i[0] ^ i[7] ^ i[10] ^ i[13]); _0[2] = (byte)(i[1] ^ i[6] ^ i[11] ^ i[12]);
o[4] = (byte)(i[0] ^ i[5] ^ i[11] ^ i[14]); _0[3] = (byte)(i[0] ^ i[7] ^ i[10] ^ i[13]);
o[5] = (byte)(i[1] ^ i[4] ^ i[10] ^ i[15]); _0[4] = (byte)(i[0] ^ i[5] ^ i[11] ^ i[14]);
o[6] = (byte)(i[2] ^ i[7] ^ i[9] ^ i[12]); _0[5] = (byte)(i[1] ^ i[4] ^ i[10] ^ i[15]);
o[7] = (byte)(i[3] ^ i[6] ^ i[8] ^ i[13]); _0[6] = (byte)(i[2] ^ i[7] ^ i[9] ^ i[12]);
o[8] = (byte)(i[1] ^ i[7] ^ i[11] ^ i[13]); _0[7] = (byte)(i[3] ^ i[6] ^ i[8] ^ i[13]);
o[9] = (byte)(i[0] ^ i[6] ^ i[10] ^ i[12]); _0[8] = (byte)(i[1] ^ i[7] ^ i[11] ^ i[13]);
o[10] = (byte)(i[3] ^ i[5] ^ i[9] ^ i[15]); _0[9] = (byte)(i[0] ^ i[6] ^ i[10] ^ i[12]);
o[11] = (byte)(i[2] ^ i[4] ^ i[8] ^ i[14]); _0[10] = (byte)(i[3] ^ i[5] ^ i[9] ^ i[15]);
o[12] = (byte)(i[2] ^ i[6] ^ i[9] ^ i[14]); _0[11] = (byte)(i[2] ^ i[4] ^ i[8] ^ i[14]);
o[13] = (byte)(i[3] ^ i[7] ^ i[8] ^ i[15]); _0[12] = (byte)(i[2] ^ i[6] ^ i[9] ^ i[14]);
o[14] = (byte)(i[0] ^ i[4] ^ i[11] ^ i[12]); _0[13] = (byte)(i[3] ^ i[7] ^ i[8] ^ i[15]);
o[15] = (byte)(i[1] ^ i[5] ^ i[10] ^ i[13]); _0[14] = (byte)(i[0] ^ i[4] ^ i[11] ^ i[12]);
_0[15] = (byte)(i[1] ^ i[5] ^ i[10] ^ i[13]);
if (i == o) System.arraycopy(_0, 0, o, 0, 16);
} }
} }
@@ -1,6 +1,7 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM.ciphers; package de.caydenno1.xacrypto.zekerrijndael.Global;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.BlockCipher;
import de.caydenno1.xacrypto.zekerrijndael.UnchangingData; import de.caydenno1.xacrypto.zekerrijndael.UnchangingData;
import de.caydenno1.xacrypto.hash.ROT; import de.caydenno1.xacrypto.hash.ROT;
@@ -9,7 +10,7 @@ interface CamelliaCipher {
byte[] decryptBlock(byte[] in); byte[] decryptBlock(byte[] in);
} }
public class Camellia implements CamelliaCipher { public class Camellia implements CamelliaCipher, BlockCipher {
private final long[] subkeys; private final long[] subkeys;
public Camellia(byte[] key) throws XACryptoException { public Camellia(byte[] key) throws XACryptoException {
@@ -18,6 +19,10 @@ public class Camellia implements CamelliaCipher {
genKeySchedule(key); genKeySchedule(key);
} }
public byte[] encryptBlock(byte[] in) throws XACryptoException {
return encryptBlock(in, 0, new byte[16], 0);
}
@Override @Override
public byte[] encryptBlock(byte[] in, int inputOffset, byte[] out, int outOffset) { public byte[] encryptBlock(byte[] in, int inputOffset, byte[] out, int outOffset) {
long d1 = bytes2Long(in, inputOffset); long d1 = bytes2Long(in, inputOffset);
@@ -78,8 +83,12 @@ public class Camellia implements CamelliaCipher {
} }
public byte[] decryptBlock(byte[] in) { public byte[] decryptBlock(byte[] in) {
long d1 = bytes2Long(in, 0); return decryptBlock(in, 0, new byte[16], 0);
long d2 = bytes2Long(in, 8); }
public byte[] decryptBlock(byte[] in, int inputOffset, byte[] out, int outOffset) {
long d1 = bytes2Long(in, inputOffset);
long d2 = bytes2Long(in, inputOffset + 8);
if (subkeys.length == 34) { if (subkeys.length == 34) {
d1 ^= subkeys[32]; d1 ^= subkeys[32];
@@ -129,10 +138,9 @@ public class Camellia implements CamelliaCipher {
d2 ^= subkeys[0]; d2 ^= subkeys[0];
d1 ^= subkeys[1]; d1 ^= subkeys[1];
byte[] o = new byte[16]; long2Bytes(d2, out, outOffset);
long2Bytes(d2, o, 0); long2Bytes(d1, out, outOffset + 8);
long2Bytes(d1, o, 8); return out;
return o;
} }
private void genKeySchedule(byte[] key) { private void genKeySchedule(byte[] key) {
@@ -0,0 +1,10 @@
package de.caydenno1.xacrypto.zekerrijndael.Global;
public class Galois {
public static byte gm2(byte b) { return (byte)(((((b & 0xFF) << 1) & 0xFF) ^ (((b & 0xFF) & 0x80) != 0 ? 0x1b : 0))); }
public static byte gm3(byte b) { return (byte)(gm2(b) ^ b); }
public static byte gm9(byte b) { byte g2 = gm2(b); byte g4 = gm2(g2); return (byte)(gm2(g4) ^ b); }
public static byte gm11(byte b) { byte g2 = gm2(b); byte g4 = gm2(g2); return (byte)(gm2(g4) ^ g2 ^ b); }
public static byte gm13(byte b) { byte g2 = gm2(b); byte g4 = gm2(g2); return (byte)(gm2((byte) (g4 ^ b)) ^ b); }
public static byte gm14(byte b) { byte g2 = gm2(b); byte g4 = gm2(g2); return (byte)(gm2((byte) (g4 ^ b)) ^ g2); }
}
@@ -0,0 +1,6 @@
package de.caydenno1.xacrypto.zekerrijndael.Global;
public class LE32 {
public static int read32LE(byte[] b, int off) { return (b[off] & 0xFF) | ((b[off + 1] & 0xFF) << 8) | ((b[off + 2] & 0xFF) << 16) | ((b[off + 3] & 0xFF) << 24); }
public static void write32LE(int v, byte[] b, int off) { for (int i = 0 ; i < 4 ; i++) b[off + i] = (byte) (v >>> (i * 8)); }
}
@@ -1,6 +1,7 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM; package de.caydenno1.xacrypto.zekerrijndael.Global;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.BlockCipher;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SERPENT_SBOX; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SERPENT_SBOX;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SERPENT_IBOX; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.SERPENT_IBOX;
@@ -71,6 +72,7 @@ public class Serpent implements SerpentCipher {
w[i] = Integer.rotateLeft(_0, 11); w[i] = Integer.rotateLeft(_0, 11);
} }
byte[] kb = new byte[16];
for (int i = 0 ; i < 33 ; i++) { for (int i = 0 ; i < 33 ; i++) {
int[] group = { w[8 + 4 * i], w[8 + 4 * i + 1], w[8 + 4 * i + 2], w[8 + 4 * i + 3] }; int[] group = { w[8 + 4 * i], w[8 + 4 * i + 1], w[8 + 4 * i + 2], w[8 + 4 * i + 3] };
@@ -78,7 +80,6 @@ public class Serpent implements SerpentCipher {
SBOXify(index, group, SERPENT_SBOX); SBOXify(index, group, SERPENT_SBOX);
byte[] kb = new byte[16];
for (int j = 0 ; j < 4 ; j++) for (int k = 0; k < 4; k++) kb[j * 4 + k] = (byte) (group[j] >>> (k * 8)); for (int j = 0 ; j < 4 ; j++) for (int k = 0; k < 4; k++) kb[j * 4 + k] = (byte) (group[j] >>> (k * 8));
pack(kb, K[i]); pack(kb, K[i]);
@@ -1,11 +1,13 @@
package de.caydenno1.xacrypto.zekerrijndael.GCM; package de.caydenno1.xacrypto.zekerrijndael.Global;
import de.caydenno1.xacrypto.misc.XACryptoException; import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.GCM.BlockCipher;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.TWOFISH_Q0; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.TWOFISH_Q0;
import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.TWOFISH_Q1; import static de.caydenno1.xacrypto.zekerrijndael.UnchangingData.TWOFISH_Q1;
import static de.caydenno1.xacrypto.zekerrijndael.Global.LE32.*;
public class Twofish { public class Twofish implements BlockCipher {
private final int[] K = new int[40]; private final int[] K = new int[40];
private final int[] S; private final int[] S;
private final int kW; private final int kW;
@@ -79,9 +81,8 @@ public class Twofish {
public byte[] encryptBlock(byte[] in) throws XACryptoException { public byte[] encryptBlock(byte[] in) throws XACryptoException {
if (in.length != 16) throw new XACryptoException("twofish's minimum block size is 16 bytes :(", (int)16); if (in.length != 16) throw new XACryptoException("twofish's minimum block size is 16 bytes :(", (int)16);
int[] X = new int[4]; int[] X = new int[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) X[i] = read32LE(in, i * 4) ^ K[i];
X[i] = read32LE(in, i * 4) ^ K[i];
}
for (int r = 0 ; r < 16 ; r += 2) { for (int r = 0 ; r < 16 ; r += 2) {
int t0 = h(X[0], S, kW); int t0 = h(X[0], S, kW);
@@ -89,7 +90,7 @@ public class Twofish {
int f0 = t0 + t1 + K[2 * r + 8]; int f0 = t0 + t1 + K[2 * r + 8];
int f1 = t0 + 2 * t1 + K[2 * r + 9]; int f1 = t0 + 2 * t1 + K[2 * r + 9];
X[2] = Integer.rotateRight(X[2] ^ f0, 1); X[2] = Integer.rotateRight(X[2] ^ f0, 1);
X[3] = Integer.rotateLeft(X[2], 1) ^ f1; X[3] = Integer.rotateLeft(X[3], 1) ^ f1;
t0 = h(X[2], S, kW); t0 = h(X[2], S, kW);
t1 = h(Integer.rotateLeft(X[3], 8), S, kW); t1 = h(Integer.rotateLeft(X[3], 8), S, kW);
@@ -106,8 +107,37 @@ public class Twofish {
write32LE(X[1] ^ K[7], o, 12); write32LE(X[1] ^ K[7], o, 12);
return o; return o;
} }
private static int read32LE(byte[] b, int off) { return (b[off] & 0xFF) | ((b[off + 1] & 0xFF) << 8) | ((b[off + 2] & 0xFF) << 16) | ((b[off + 3] & 0xFF) << 24); } public byte[] decryptBlock(byte[] in) throws XACryptoException {
private static void write32LE(int v, byte[] b, int off) { for (int i = 0 ; i < 4 ; i++) b[off + i] = (byte) (v >>> (i * 8)); }; if (in.length != 16) throw new XACryptoException("min block size is 16 (twofish) :(",(int)in.length);
int[] X = new int[4];
X[2] = read32LE(in, 0) ^ K[4];
X[3] = read32LE(in, 4) ^ K[5];
X[0] = read32LE(in, 8) ^ K[6];
X[1] = read32LE(in, 12) ^ K[7];
for (int r = 14 ; r >= 0 ; r -= 2) {
int t0 = h(X[2], S, kW);
int t1 = h(Integer.rotateLeft(X[3], 8), S, kW);
int f0 = t0 + t1 + K[2 * r + 10];
int f1 = t0 + 2 * t1 + K[2 * r + 11];
X[0] = Integer.rotateLeft(X[0], 1) ^ f0;
X[1] = Integer.rotateRight(X[1] ^ f1, 1);
t0 = h(X[0], S, kW);
t1 = h(Integer.rotateLeft(X[1], 8), S, kW);
f0 = t0 + t1 + K[2 * r + 8];
f1 = t0 + 2 * t1 + K[2 * r + 9];
X[2] = Integer.rotateLeft(X[2], 1) ^ f0;
X[3] = Integer.rotateRight(X[3] ^ f1, 1);
}
byte[] o = new byte[16];
for (int i = 0 ; i < 4 ; i++) write32LE(X[i] ^ K[i], o, i*4);
return o;
}
private static int gfMultMDS(int a, int b) { private static int gfMultMDS(int a, int b) {
int p = 0; int p = 0;
for (int i = 0 ; i < 8 ; i++) { for (int i = 0 ; i < 8 ; i++) {