# Analysis of Key Storage Mechanism of Asymmetric Key-Related Functions in CNG Crypto Library
## 3 Methodology
### Discussion  
The derived information that is used for the decryption based on the result of the analysis is the copied value of the cipher text backward, the address of offset 0x70 of the address of offset 0 xC of the key handle address, the address of offset 0x40 of the address of offset 0 xC of the key handle address, the address of offset 0x48 of the address of offset 0 xC of the key handle address, the address of offset 0 xAC of the address of offset 0 xC of the key handle address, the address of offset 0x44 of the address of offset 0 xC of the key handle address, and the address of offset 0x4C of the key address of offset 0x4C of the key address. Figures 38-41 show the decryption process (response to Question 2).  
Figure 37: The decrypted result (RSA).  
Figure 36: The second operation result of the fourth CALL (RSA).  
Finally, we tried to analyze the key storage location of NCrypt based on the analyzed BCrypt decryption process. The result of calling the internal function after setting the breakpoint on the NCryptDecrypt function, the NdrSendReceive function of the rpcrt4 library, is called from the inside, as shown in Figure 42. Inside the NdrSendReceive function, the I_RpcSendReceive function is called, as shown in Figure 43, and the ZwAlpcSendWaitReceivePort function of the ntdll library is called inside the I_RpcSendReceive function, as shown in Figure 44. Inside the ZwAlpcSendWaitReceivePort function, the kernel code is executed in the kernel, and the decryption result is returned after the function is called, as shown in Figure 45.  
Figure 38: Decryption process diagram 1 (RSA).  
Figure 39: Decryption process diagram 2 (RSA).  
Figure 41: Whole decryption process diagram.  
Figure 40: Decryption process diagram 3 (RSA).  
This article analyzed the key storage mechanism in the asymmetric-key-related functions of the CNG library and derived two research questions. The first question is whether it is possible to verify real key information from the obtained handle because CNG does not directly receive key information during the encryption and decryption processes. The second question is as follows: \"If the handle address of an encryption or decryption key is given, can the location of the real key information be analyzed from the key handle address?\" In answer to the first question, it was not possible to analyze the exact location using the key handle based on the key information obtained when the key was loaded in NCrypt. As shown in Figure 41, the response to the second question accurately analyzed the key storage mechanism in asymmetric-key-related functions in BCrypt. Based on these questions and responses, the analyzed results can be used for the purpose of verifying key-related information, such as debugging and verification, when developing various cryptographic systems and application programs using CNG. Furthermore, if a tool for extracting key information is implemented, we believe that an automated key verification method can be developed.  
Figure 44: The internal calling process of NCryptDecrypt function 3 (RSA).  
Figure 43: The internal calling process of NCryptDecrypt function 2 (RSA).  
Figure 42: The internal calling process of NCryptDecrypt function 1 (RSA).  
Figure 45: The internal calling process of NCryptDecrypt function 4 (RSA).