Skip to content

Commit

Permalink
reverted some changes to get ml-kem working (passes acvp test, not su…
Browse files Browse the repository at this point in the history
…re if ACVP is up to date)
  • Loading branch information
royb committed Aug 13, 2024
1 parent 953ef6b commit df71b64
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ byte[][] generateKeyPair(byte[] d)
// (p, sigma) <- G(d || k)

byte[] buf = new byte[64];
symmetric.hash_g(buf, Arrays.concatenate(d, Pack.intToLittleEndian(kyberK)));
//TODO: specs specifies K to be concatenated to with d but acvp tests says otherwise
symmetric.hash_g(buf, d);
// byte[] k = new byte[1];
// k[0] = (byte)kyberK;
// symmetric.hash_g(buf, Arrays.concatenate(d, k));

byte[] publicSeed = new byte[32]; // p in docs
byte[] noiseSeed = new byte[32]; // sigma in docs
Expand Down Expand Up @@ -177,7 +181,7 @@ public byte[] encrypt(byte[] publicKeyInput, byte[] msg, byte[] coins)
aMatrixTranspose[i] = new PolyVec(engine);
}

generateMatrix(aMatrixTranspose, seed, false);
generateMatrix(aMatrixTranspose, seed, true);

// System.out.print("matrix transposed = ");
// for (i = 0; i < kyberK; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ public SecretWithEncapsulation generateEncapsulated(AsymmetricKeyParameter recip
byte[][] kemEncrypt = engine.kemEncrypt(key.getEncoded(), randBytes);
return new SecretWithEncapsulationImpl(kemEncrypt[0], kemEncrypt[1]);
}
public SecretWithEncapsulation internalGenerateEncapsulated(AsymmetricKeyParameter recipientKey, byte[] randBytes)
{
KyberPublicKeyParameters key = (KyberPublicKeyParameters)recipientKey;
KyberEngine engine = key.getParameters().getEngine();
engine.init(sr);

byte[][] kemEncrypt = engine.kemEncryptInternal(key.getEncoded(), randBytes);
return new SecretWithEncapsulationImpl(kemEncrypt[0], kemEncrypt[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ public AsymmetricCipherKeyPair generateKeyPair()
return genKeyPair();
}

public AsymmetricCipherKeyPair internalGenerateKeyPair(byte[] d, byte[] z)
{
byte[][] keyPair = kyberParams.getEngine().generateKemKeyPairInternal(d, z);

KyberPublicKeyParameters pubKey = new KyberPublicKeyParameters(kyberParams, keyPair[0], keyPair[1]);
KyberPrivateKeyParameters privKey = new KyberPrivateKeyParameters(kyberParams, keyPair[2], keyPair[3], keyPair[4], keyPair[0], keyPair[1]);

return new AsymmetricCipherKeyPair(pubKey, privKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getName()
return name;
}

KyberEngine getEngine()
public KyberEngine getEngine()
{
return new KyberEngine(k, usingAes);
}
Expand Down

0 comments on commit df71b64

Please sign in to comment.