Skip to content

Instantly share code, notes, and snippets.

@cemeyer
Created January 22, 2019 17:44
Show Gist options
  • Save cemeyer/7ebafafc616830faf6fec5c9f1abaa9b to your computer and use it in GitHub Desktop.
Save cemeyer/7ebafafc616830faf6fec5c9f1abaa9b to your computer and use it in GitHub Desktop.
rsa/ctkip/a/i.java, decoded slightly (may not compile, I didn't try)
package com.rsa.ctkip.a;
import com.rsa.ctkip.b.a.a;
import com.rsa.ctkip.b.a.b;
import com.rsa.ctkip.b.a.c;
public class i {
private static byte[] ct_kip_prf_aes(byte[] key, byte[] msg, int i) {
return cmac_block(key, msg, 1);
}
public static byte[] a(byte[] client_nonce, byte[] server_nonce, int i, String str) {
if (str.equals(b.b)) {
String cMac2C = "MAC 2 Computation";
byte obj[] = new byte[(cMac2C.length() + client_nonce.length)];
System.arraycopy(cMac2C.getBytes(), 0, obj, 0, cMac2C.length());
System.arraycopy(client_nonce, 0, obj, cMac2C.length() + 0, client_nonce.length);
return ct_kip_prf_aes(server_nonce, obj, i);
}
throw new RuntimeException("unhandled PRF");
}
public static byte[] a(byte[] client_nonce, byte[] server_nonce, byte[] rsa_mod, int i, String str) {
if (str.indexOf("ct-kip-prf-aes") != -1) {
String ckeygen = "Key generation";
byte obj[] = new byte[((rsa_mod.length + ckeygen.length()) + server_nonce.length)];
System.arraycopy(rsa_mod, 0, obj, 0, rsa_mod.length);
byte bkeygen[] = ckeygen.getBytes();
System.arraycopy(bkeygen, 0, obj, rsa_mod.length, bkeygen.length);
System.arraycopy(server_nonce, 0, obj, ckeygen.length() + rsa_mod.length, server_nonce.length);
return ct_kip_prf_aes(client_nonce, obj, i);
}
throw new RuntimeException("unhandled PRF");
}
public static byte[] b(byte[] bArr, byte[] bArr2, byte[] xxxKey, int i, String str) {
if (str.equals(b.b)) {
byte[] bArr4;
String str2 = "MAC 1 Computation";
if (bArr != null) {
bArr4 = new byte[((bArr.length + str2.length()) + bArr2.length)];
System.arraycopy(str2.getBytes(), 0, bArr4, 0, str2.length());
int length = str2.length() + 0;
System.arraycopy(bArr, 0, bArr4, length, bArr.length);
System.arraycopy(bArr2, 0, bArr4, length + bArr.length, bArr2.length);
} else {
bArr4 = new byte[(str2.length() + bArr2.length)];
System.arraycopy(str2, 0, bArr4, 0, str2.length());
System.arraycopy(bArr2, 0, bArr4, str2.length() + 0, bArr2.length);
}
return ct_kip_prf_aes(xxxKey, bArr4, i);
}
throw new RuntimeException("unhandled PRF");
}
private static byte[] cmac_block(byte[] key, byte[] msg, int blockno) {
// probably AES key scheduling
c aes_key_variable = new c();
aes_key_variable.a(key, 128, 1);
// initialize AES-CMAC with scheduled key material
a aes_cmac = new a(aes_key_variable);
// ::Init()
aes_cmac.a();
// cmac_buf = msg || be32(blockno)
byte[] cmac_buf = new byte[(msg.length + 4)];
System.arraycopy(msg, 0, cmac_buf, 0, msg.length);
// append big-endian 32-bit block number after msg in cmac_buf
cmac_buf[cmac_buf.length - 1] = (byte) blockno;
int i2 = blockno / 256;
cmac_buf[cmac_buf.length - 2] = (byte) i2;
i2 /= 256;
cmac_buf[cmac_buf.length - 3] = (byte) i2;
cmac_buf[cmac_buf.length - 4] = (byte) (i2 / 256);
// ::Update(msg || be32(blockno))
aes_cmac.a(cmac_buf, cmac_buf.length);
// noop
cmac_buf = new byte[16];
// ::Digest()
return aes_cmac.c();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment