2015-06-10 60 views
1

我正在寫一個JBenchX方法,它使用flexiprovider計算CMSS簽名的密鑰。我想爲我的方法createKeys獲取時間,但這非常慢。沒有annnotation @Bench太快了< 1秒。你能幫助理解這裏發生了什麼嗎?JBenchX日食很慢

import de.flexiprovider.api.exceptions.NoSuchAlgorithmException; 
import de.flexiprovider.api.keys.KeyPair; 
import de.flexiprovider.api.keys.KeyPairGenerator; 
import org.jbenchx.annotations.Bench; 
import org.jbenchx.annotations.ForEachInt; 
import org.jbenchx.annotations.ForEachString; 
import org.jbenchx.annotations.SingleRun; 

public class CMSSTest { 

@Bench 
public Object createKeys(@ForEachString({ "CMSSwithSHA1andWinternitzOTS_1" }) String cmss) throws NoSuchAlgorithmException { 
    Security.addProvider(new FlexiPQCProvider()); 

     //byte[] signatureBytes = null; 
     KeyPairGenerator kpg = (CMSSKeyPairGenerator) Registry 
       .getKeyPairGenerator(cmss); 
     KeyPair keyPair = kpg.genKeyPair(); 
} 
} 

實際輸出是並且是活動的。

初始化基準框架... 在Linux上運行的Linux 最大堆= 1345847296系統基準= 11,8ns 執行1個基準測試任務.. [0] CMSSTest.createObjectArray(CMSSwithSHA1andWinternitzOTS_1)!*!** !! !****** !! ******!****!**** !! ****** !!!! *******!***** *!****!*********************************

回答

1

問題似乎是這樣的Registry.getKeyPairGenerator創建一個新的KeyPairGenerator,該KeyPairGenerator使用'true'隨機種子進行初始化。爲此,系統可能需要等待足夠的熵可用。因此,您不應該將其作爲您想要進行基準測試的代碼的一部分。

嘗試這樣:

import java.security.Security; 

import org.jbenchx.annotations.Bench; 
import org.jbenchx.annotations.ForEachString; 

import de.flexiprovider.api.Registry; 
import de.flexiprovider.api.exceptions.NoSuchAlgorithmException; 
import de.flexiprovider.api.keys.KeyPair; 
import de.flexiprovider.api.keys.KeyPairGenerator; 
import de.flexiprovider.pqc.FlexiPQCProvider; 

public class CMSSTest { 

    static { 
    Security.addProvider(new FlexiPQCProvider()); 
    } 

    private final KeyPairGenerator kpg; 

    public CMSSTest(@ForEachString({"CMSSwithSHA1andWinternitzOTS_1"}) String cmss) throws NoSuchAlgorithmException { 
    this.kpg = Registry.getKeyPairGenerator(cmss); 
    } 

    @Bench 
    public Object createKeys() { 
    KeyPair keyPair = kpg.genKeyPair(); 
    return keyPair; 
    } 
}