Zeker rijndael (#10)

* Update README.md (#2)

* AES128.java + UnchangedData.java

* Several ciphers, alot of ZekerRijndael progress

* maak de j0-functie aan

* maak een inc32-functie aan

* progress!

* GCM.java complete!

* my dementia .. lol

* SM4 COMPLET!

* decryption bugfix

* easy

making these were so easy, just had to copy and paste AES128 and change like 5 numbers

* read desc

i feel sick. i made the rest of the functions dummy functions and will finish them in the future. i am unsure if i will continue working on this tomorrow, i may take a break or i may not, who knows.

* F func finished in Camellia. several bugfixes

feel much better btw, took a shower and slept :)

* FL don

would recommend deleting .idea when you clone. FL done

* Camellia

Camellia complete

* add factory

* bugfix,more consise

* Fixed very annoying seperate AES<bitcount>.java files into one unified AES.java file :D (#4)

* AES.java potential

* Update AES.java

bufxie

* remove old libs

removed old AES$.java files as they are deprecated now that AES.java is created. (AES.java should be 100% functional.)

* Update Factories.java

aaand rename the AES128 factory to use AES with bits:128 instead of AES128

* Update AES.java

Performance Enhancements

PKCS#7 OK!

Safety (missing bounds protection)

* Update README.md (#5)

* Update AES.java

ah yes i love things magically stop working after PR ! :P

* something idk

my head is hurting again! :D so fun. i might make AESGCM.java use GHASH.java's xor function if i can figure out why its not working. also AESGCM.java (in its current state) sucks. i need to work on it a bit but just not now.

* update gitignore

* uh

how did it break? i didnt even change either of those files since they were working

* very legit solution 4realz1

* useless

* fix (#7)

* GHASH compnonce + fixed AESGCM bugs

* Update AES.java

some fixes.

* Update AESGCM.java

add warning

* Camelia

performance enhancements + decryption (i forgot to add it before lol) + several bugfixes

* "It's not a disaster, It's innovation!"

* decryption + bufixes

* Update Project_Default.xml

* this isnt English class

* Update README.md

it duplicated itself lol

* desc

Aria.java progress, next commit will have GRK finished

* Aria.java complete!

* desc

added support for Camelia 192 + 256 bit operation, perf enhancements and bugfixes

* add ARIAGCM factory

my wrapper in ARIAGCM handles GCM :)

* Update README.md

add TODO

* added 128,192,256 support for AESGCM

* desc

soo... did you know sometimes you actually do want to reuse code without getting 68 warnings from intellij?

* note+camellia tab

* began Serpant.java

* Serpent COMPLET!

* desc

add dummy functions to twofish

* Update Twofish.java

progrses on twofish + HUMOR

* twofish done + readme upd

* HOLY

i actually finished Blowfish.java lol, almost done with ECB, just neeed 2 functions

* Bfish ECB done! :D

* desc

- fix typo

- add Aria.java support for Aria-ECB

- move Aria.java to globalpackaeg

* Create AriaECB.java

will finish this tmr. im so tired lol

* desc

ariaecb complete, also forgot to add factories for blowfish too

* Update AriaECB.java

* sm4ecb complete
This commit is contained in:
Xiao X
2026-06-02 12:34:10 -04:00
committed by GitHub
parent 8561029b26
commit 413b038b8a
32 changed files with 2042 additions and 51 deletions
@@ -0,0 +1,62 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.Global.Aria;
interface AriaCipher {
public byte[] encrypt(byte[] pln) throws XACryptoException;
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
public class AriaECB implements AriaCipher {
private final Aria engine;
public AriaECB(byte[] key) throws XACryptoException {
this.engine = new Aria(true,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[] out = engine.encryptBlock(in);
System.arraycopy(out, 0, cip, i, 16);
}
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length % 16 != 0) throw new XACryptoException("length of ciphertext must be a multiple of 16 (16-byte size) :-{");
byte[] Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint = 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[] out = engine.decryptBlock(in);
System.arraycopy(out,0, Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint, i, 16);
}
int pLen = Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint[Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint.length - 1] & 0xFF;
if (pLen < 1 || pLen > 16) throw new XACryptoException("padding must be 1-16 exclusive in length", (int)pLen);
byte[] pln = new byte[Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint.length - pLen];
System.arraycopy(Microsoft_PowerPoint_Create_polished_slides_in_minutes_using_AI_driven_design_and_collaboration_tools_in_PowerPoint,0,pln,0,pln.length);
return pln;
}
}
@@ -0,0 +1,47 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
import de.caydenno1.xacrypto.zekerrijndael.ECB.Blowfish;
interface BlowfishCipher {
public byte[] encrypt(byte[] pln);
public byte[] decrypt(byte[] cip) throws XACryptoException;
}
public class BlowfishECB implements BlowfishCipher {
private final Blowfish engine;
public BlowfishECB(byte[] key) throws XACryptoException {
this.engine = new Blowfish(key);
}
public byte[] encrypt(byte[] pln) {
int pLen = 8 - (pln.length % 8);
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 += 8) engine.encryptBlock(pData, i, cip, i);
return cip;
}
public byte[] decrypt(byte[] cip) throws XACryptoException {
if (cip.length == 0 || cip.length % 8 != 0) throw new XACryptoException("ciptext must be bound to 8-byte alignment (<-- sum like that)");
byte[] Microsoft_PowerPoint /* https://merriam-webster.com/dictionary/satire */= new byte[cip.length];
for (int i = 0 ; i < cip.length ; i += 8) engine.decryptBlock(cip, i, Microsoft_PowerPoint, i);
int pLen = Microsoft_PowerPoint[Microsoft_PowerPoint.length - 1] & 0xFF;
if (pLen < 1 || pLen > 8) throw new XACryptoException("cirrupt data , padding must be 1-8 bytes exclusive", (int)pLen);
for (int i = Microsoft_PowerPoint.length - pLen ; i < Microsoft_PowerPoint.length ; i++) if (((Microsoft_PowerPoint[i] & 0xFF) != pLen)) throw new XACryptoException("something up with yo padding.. :(");
byte[] pln = new byte[Microsoft_PowerPoint.length - pLen];
System.arraycopy(Microsoft_PowerPoint, 0, pln, 0, pln.length);
return pln;
}
}
@@ -0,0 +1,122 @@
package de.caydenno1.xacrypto.zekerrijndael.ECB.ciphers;
import de.caydenno1.xacrypto.misc.XACryptoException;
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_SBOX;
import static de.caydenno1.xacrypto.hash.ROT.ROTL;
interface SM4Cipher {
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[] decRK = new int[32];
public SM4ECB(byte[] key) throws XACryptoException {
if (key.length != 16) throw new XACryptoException("key length must be 16 bytes :{", (int) key.length);
genRK(key);
}
private void genRK(byte[] key) {
int[] K = new int[36];
for (int i = 0; i < 4; i++) K[i] = BYTE2INT(key, i * 4) ^ SM4_FK[i];
for (int i = 0 ; i < 32 ; i++) {
int _0 = K[i + 1] ^ K[i + 2] ^ K[i + 3] ^ SM4_CK[i];
int b = ((SM4_SBOX[(_0 >>> 24) & 0xFF]) << 24)
| ((SM4_SBOX[(_0 >>> 16) & 0xFF]) << 16)
| ((SM4_SBOX[(_0 >>> 8) & 0xFF]) << 8)
| (SM4_SBOX[_0 & 0xFF]);
int l = b ^ ROTL(b, 13) ^ ROTL(b, 23);
K[i + 4] = K[i] ^ l;
this.encRK[i] = K[i + 4];
this.decRK[31 - i] = K[i + 4];
}
}
private void processBlock(byte[] in, int inOff, byte[] o, int outOff, int[] rk) {
int[] X = new int[5];
for (int i = 0; i < 4; i++) X[i] = BYTE2INT(in, inOff + (i * 4));
for (int i = 0 ; i < 32 ; i++) {
int tmp = X[1] ^ X[2] ^ X[3] ^ rk[i];
int b = ((SM4_SBOX[(tmp >>> 24) & 0xFF]) << 24)
| ((SM4_SBOX[(tmp >>> 16) & 0xFF]) << 16)
| ((SM4_SBOX[(tmp >>> 8) & 0xFF]) << 8)
| (SM4_SBOX[tmp & 0xFF]);
int l = b ^ ROTL(b, 2) ^ ROTL(b, 10) ^ ROTL(b, 18) ^ ROTL(b, 24);
X[4] = X[0] ^ l;
X[0] = X[1];
X[1] = X[2];
X[2] = X[3];
X[3] = X[4];
}
for (int i = 0; i < 4; i++) INT2BYTE(X[3 - i], o, outOff + (i * 4));
}
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];
byte[] in = new byte[16];
byte[] o = new byte[16];
for (int i = 0; i < pData.length; i += 16) {
System.arraycopy(pData, i, in, 0, 16);
processBlock(in, 0, o, 0, encRK);
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 ciphertext must be a multiple of 16 (16-byte size) :-{");
}
byte[] decomp = new byte[cip.length];
byte[] _i = new byte[16];
byte[] o = new byte[16];
for (int i = 0; i < cip.length; i += 16) {
System.arraycopy(cip, i, _i, 0, 16);
processBlock(_i, 0, o, 0, decRK);
System.arraycopy(o, 0, decomp, i, 16);
}
int pLen = decomp[decomp.length - 1] & 0xFF;
if (pLen < 1 || pLen > 16) throw new XACryptoException("padding must be 1-16 exclusive in length", (int) pLen);
byte[] pln = new byte[decomp.length - pLen];
System.arraycopy(decomp, 0, pln, 0, pln.length);
return pln;
}
private static int BYTE2INT(byte[] b, int off) {
return ((b[off] & 0xFF) << 24) |
((b[off + 1] & 0xFF) << 16) |
((b[off + 2] & 0xFF) << 8) |
(b[off + 3] & 0xFF);
}
private static void INT2BYTE(int v, byte[] b, int o) {
for (int i = 0; i < 4; i++) b[o + i] = (byte) (v >>> (24 - 8 * i));
}
}