I am trying to find the implementations of the source code.
For example, if I initialize the Cipher-object like this:
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
how can I find the actual implementaion of the AES-Algorithm that is used and of the CTR-mode?
If I am looking up the source code of Cipher.java than you can see that the getInstance()-method uses some service-providers. I am guessing that the line:
List<Service> services = GetInstance.getServices(cipherServices);
is responsible for matching the "AES/CTR/NoPadding" to the CipherSpi-object that is created.
But now I am stuck and I do not know what is going on. How is this working? Where can I find the source code to AES and CTR? Is it matched to the classes in this .../sun/crypto/provider folder? How does this matching work? Where can I see what is matched to what input? What I am also trying to figure out is if the CTR-Mode uses some sort of parallelism.
The
Cipher
object has a methodgetProvider()
to return theProvider
instance, that was used to create theCipher
object. This class has several methods to get information about the provider itself like the name. You can use this information to "reverse engineer" which class or package is implementing the cipher. See the following example:This can generate an output like this (with openjdk version "1.8.0_362"):
You can check the JDK or any installed provider JAR (like BouncyCastle) for the implementation class. For OpenJDK, the implementation of that class is at https://github.com/openjdk/jdk/blob/b3cc0c84316dd59f406a6fa23fcaf3d029910843/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java. From there you can check other related classes like
AESCipher
orAESCrypt
.