mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 02:30:25 +08:00
add:添加sm234与keychain的不同包长性能测试
This commit is contained in:
@@ -11,6 +11,7 @@ import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.eclipse.collections.api.partition.ordered.PartitionReversibleIterable;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
@@ -32,13 +33,48 @@ public class SM2Benchmark {
|
||||
private static SM2PublicKey sm2PublicKey;
|
||||
private static byte[] digest;
|
||||
private static byte[] encBytes;
|
||||
private static String content2;
|
||||
private static byte[] digest1K;
|
||||
private static byte[] encBytes1K;
|
||||
private static byte[] digest8K;
|
||||
private static byte[] encBytes8K;
|
||||
private static byte[] payLoad;
|
||||
private static byte[] payLoad1K;
|
||||
private static byte[] payLoad8K;
|
||||
|
||||
private static byte[] createPayload(int mode){
|
||||
byte[] res = null;
|
||||
switch (mode){
|
||||
case 0:
|
||||
return new byte[]{1};
|
||||
case 1:
|
||||
res = new byte[1024];
|
||||
for (int i = 0; i < 1024 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
case 8:
|
||||
res = new byte[8192];
|
||||
for (int i = 0; i < 8192 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
init(); // 初始化类成员公私钥
|
||||
digest = sm2PrivateKey.sign(ByteUtils.fromHexString(content)); // 初始化类成员摘要
|
||||
content2 = "hello world";
|
||||
encBytes = sm2PublicKey.encrypt(content2.getBytes());
|
||||
payLoad = createPayload(0);
|
||||
payLoad1K = createPayload(1);
|
||||
payLoad8K = createPayload(8);
|
||||
digest = sm2PrivateKey.sign(payLoad); // 初始化类成员摘要
|
||||
encBytes = sm2PublicKey.encrypt(payLoad);
|
||||
digest1K = sm2PrivateKey.sign(payLoad1K); // 初始化类成员摘要
|
||||
encBytes1K = sm2PublicKey.encrypt(payLoad1K);
|
||||
digest8K = sm2PrivateKey.sign(payLoad8K); // 初始化类成员摘要
|
||||
encBytes8K = sm2PublicKey.encrypt(payLoad8K);
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -60,12 +96,32 @@ public class SM2Benchmark {
|
||||
|
||||
@Benchmark
|
||||
public void testSign() throws CryptoException {
|
||||
SM2Benchmark.sm2PrivateKey.sign(ByteUtils.fromHexString(content));
|
||||
SM2Benchmark.sm2PrivateKey.sign(payLoad);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerify() throws CryptoException {
|
||||
SM2Benchmark.sm2PublicKey.verify(ByteUtils.fromHexString(content), digest);
|
||||
SM2Benchmark.sm2PublicKey.verify(payLoad, digest);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSign1K() throws CryptoException {
|
||||
SM2Benchmark.sm2PrivateKey.sign(payLoad1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerify1K() throws CryptoException {
|
||||
SM2Benchmark.sm2PublicKey.verify(payLoad1K, digest1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSign8K() throws CryptoException {
|
||||
SM2Benchmark.sm2PrivateKey.sign(payLoad8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerify8K() throws CryptoException {
|
||||
SM2Benchmark.sm2PublicKey.verify(payLoad8K, digest8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@@ -75,13 +131,33 @@ public class SM2Benchmark {
|
||||
|
||||
@Benchmark
|
||||
public void testEncrypt() throws InvalidCipherTextException {
|
||||
sm2PublicKey.encrypt(content2.getBytes());
|
||||
sm2PublicKey.encrypt(payLoad);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testDecrypt() throws InvalidCipherTextException {
|
||||
sm2PrivateKey.decrypt(encBytes);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testEncrypt1K() throws InvalidCipherTextException {
|
||||
sm2PublicKey.encrypt(payLoad1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testDecrypt1K() throws InvalidCipherTextException {
|
||||
sm2PrivateKey.decrypt(encBytes1K);
|
||||
}
|
||||
@Benchmark
|
||||
public void testEncrypt8K() throws InvalidCipherTextException {
|
||||
sm2PublicKey.encrypt(payLoad8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testDecrypt8K() throws InvalidCipherTextException {
|
||||
sm2PrivateKey.decrypt(encBytes8K);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(SM2Benchmark.class.getSimpleName())
|
||||
|
||||
@@ -18,9 +18,36 @@ import java.util.concurrent.TimeUnit;
|
||||
public class SM3Benchmark {
|
||||
private static HashAlgo hashAlgo;
|
||||
private static String srcString = "123456";
|
||||
private static byte[] srcData = srcString.getBytes();
|
||||
private static byte[] srcData, srcData1K, srcData8K;
|
||||
static {
|
||||
hashAlgo = new HashAlgo();
|
||||
srcData = createPayload(0);
|
||||
srcData1K = createPayload(1);
|
||||
srcData8K = createPayload(8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static byte[] createPayload(int mode){
|
||||
byte[] res = null;
|
||||
switch (mode){
|
||||
case 0:
|
||||
return new byte[]{1};
|
||||
case 1:
|
||||
res = new byte[1024];
|
||||
for (int i = 0; i < 1024 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
case 8:
|
||||
res = new byte[8192];
|
||||
for (int i = 0; i < 8192 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@@ -28,6 +55,16 @@ public class SM3Benchmark {
|
||||
hashAlgo.sm3(srcData);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSM31K(){
|
||||
hashAlgo.sm3(srcData1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSM38K(){
|
||||
hashAlgo.sm3(srcData8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSM3ByString(){
|
||||
hashAlgo.sm3(srcString);
|
||||
|
||||
@@ -28,23 +28,68 @@ import static minsecurity.crypto.TestSM4.SRC_DATA_16B;
|
||||
public class SM4Benchmark {
|
||||
private static byte[] key;
|
||||
private static byte[] iv;
|
||||
private static byte[] payLoad, payLoad1K, payLoad8K;
|
||||
private static byte[] cipherText;
|
||||
private static byte[] cipherText2;
|
||||
private static byte[] cipherText3;
|
||||
private static byte[] cipherText4;
|
||||
private static byte[] cipherText5;
|
||||
private static byte[] cipherText6;
|
||||
|
||||
|
||||
private static byte[] createPayload(int mode){
|
||||
byte[] res = null;
|
||||
switch (mode){
|
||||
case 0:
|
||||
return new byte[]{1};
|
||||
case 1:
|
||||
res = new byte[1024];
|
||||
for (int i = 0; i < 1024 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
case 8:
|
||||
res = new byte[8192];
|
||||
for (int i = 0; i < 8192 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
key = SM4.generateKey();
|
||||
iv = SM4.generateKey();
|
||||
cipherText = SM4.encrypt_ECB_Padding(key, SRC_DATA_16B);
|
||||
cipherText2 = SM4.encrypt_CBC_Padding(key, iv, SRC_DATA);
|
||||
payLoad = createPayload(0);
|
||||
payLoad1K = createPayload(1);
|
||||
payLoad8K = createPayload(8);
|
||||
cipherText = SM4.encrypt_ECB_Padding(key, payLoad);
|
||||
cipherText2 = SM4.encrypt_CBC_Padding(key, iv, payLoad);
|
||||
cipherText3 = SM4.encrypt_ECB_Padding(key, payLoad1K);
|
||||
cipherText4 = SM4.encrypt_CBC_Padding(key, iv, payLoad1K);
|
||||
cipherText5 = SM4.encrypt_ECB_Padding(key, payLoad8K);
|
||||
cipherText6 = SM4.encrypt_CBC_Padding(key, iv, payLoad8K);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCEncrypt() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_CBC_Padding(key, iv, payLoad);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCDecrypt() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_CBC_Padding(key, iv, cipherText2);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testECBEncrypt() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_ECB_Padding(key, SRC_DATA_16B);
|
||||
SM4.encrypt_ECB_Padding(key, payLoad);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@@ -53,13 +98,43 @@ public class SM4Benchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCEncrypt() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_CBC_Padding(key, iv, SRC_DATA);
|
||||
public void testCBCEncrypt1K() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_CBC_Padding(key, iv, payLoad1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCDecrypt() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_CBC_Padding(key, iv, cipherText2);
|
||||
public void testCBCDecrypt1K() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_CBC_Padding(key, iv, cipherText4);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testECBEncrypt1K() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_ECB_Padding(key, payLoad1K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testECBDecrypt1K() throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_ECB_Padding(key, cipherText3);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCEncrypt8K() throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_CBC_Padding(key, iv, payLoad8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCBCDecrypt8K() throws BadPaddingException, NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_CBC_Padding(key, iv, cipherText6);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testECBEncrypt8K() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.encrypt_ECB_Padding(key, payLoad8K);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testECBDecrypt8K() throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException {
|
||||
SM4.decrypt_ECB_Padding(key, cipherText5);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PersistBenchmark {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
@@ -66,7 +66,7 @@ public class PersistBenchmark {
|
||||
|
||||
@Benchmark
|
||||
public void testSetIdentity() throws Exception {
|
||||
String name = "wzq0.6597381351293033"; // 预先存储好的身份名
|
||||
String name = "/wzq0.6597381351293033"; // 预先存储好的身份名
|
||||
Persist.setDefaultIdentityByNameInStorage(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TestIdentity {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TestPersist {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class IdentifyManagerBenchmark {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class IdentifyManagerTest {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package security;
|
||||
|
||||
import component.ComponentException;
|
||||
import component.Identifier;
|
||||
import component.TTL;
|
||||
import encoding.VlInt;
|
||||
@@ -9,6 +10,7 @@ import minsecurity.certificate.cert.Certificate;
|
||||
import minsecurity.crypto.sm2.SM2KeyPair;
|
||||
import minsecurity.identity.Identity;
|
||||
import minsecurity.identity.KeyParam;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
@@ -35,7 +37,7 @@ public class KeychainBenchmark {
|
||||
// 测试PersistIdentity
|
||||
SM2KeyPair pair = SM2KeyPair.generateKeyPair();
|
||||
Identity identity = new Identity();
|
||||
identity.setName("wzq"+Math.random());
|
||||
identity.setName("/wzq"+Math.random());
|
||||
KeyParam keyParam = new KeyParam();
|
||||
keyParam.PublicKeyAlgorithm = 0;
|
||||
keyParam.SignatureAlgorithm = 0;
|
||||
@@ -64,33 +66,38 @@ public class KeychainBenchmark {
|
||||
return identity;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testCreateKeyChain() throws Exception {
|
||||
KeyChain keyChain = new KeyChain();
|
||||
private static KeyChain chain;
|
||||
|
||||
private static Interest interest, interest2, interest3, interest4, interest5, interest6; // 用于签名
|
||||
|
||||
private static Data data, data2, data3, data4, data5, data6; // 用于签名
|
||||
|
||||
private static CPacket cPacket, cPacket2, cPacket3, cPacket4, cPacket5, cPacket6; // 用于签名
|
||||
private static byte[] createPayload(int mode){
|
||||
byte[] res = null;
|
||||
switch (mode){
|
||||
case 0:
|
||||
return new byte[]{1};
|
||||
case 1:
|
||||
res = new byte[1024];
|
||||
for (int i = 0; i < 1024 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
case 8:
|
||||
res = new byte[8192];
|
||||
for (int i = 0; i < 8192 ; i++) {
|
||||
res[i] = (byte) (i % 128);
|
||||
}
|
||||
return res;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testInitialKeyChain() throws Exception {
|
||||
// 测试设置新身份为当前身份
|
||||
KeyChain keyChain = new KeyChain();
|
||||
// Identity id = createRandomIdentity();
|
||||
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// 输入密码用于解锁身份
|
||||
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignAndVerifyInterest() throws Exception {
|
||||
// 测试设置新身份为当前身份
|
||||
KeyChain keyChain = new KeyChain();
|
||||
// Identity id = createRandomIdentity();
|
||||
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// 输入密码用于解锁身份
|
||||
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
|
||||
private static Interest createInterest(byte[] payload) throws ComponentException {
|
||||
// 身份允许签名与验证签名
|
||||
Identifier id1 = new Identifier("/min/pku/sz");
|
||||
Identifier id2 = new Identifier("/install");
|
||||
|
||||
//////////////////// 构建兴趣包 ////////////////////////
|
||||
Interest interest = new Interest();
|
||||
@@ -102,24 +109,23 @@ public class KeychainBenchmark {
|
||||
interest.hopLimit.setHopLimit(1234);
|
||||
interest.congestionMark.setCongestionLevel(1234);
|
||||
interest.ttl.setTtl(1234);
|
||||
interest.payload.setValue(new byte[]{1, 2, 3, 4, 5});
|
||||
interest.payload.setValue(payload);
|
||||
|
||||
|
||||
// 正常测试签名与验签
|
||||
keyChain.signInterest(interest);
|
||||
keyChain.verifyInterest(interest);
|
||||
return interest;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignAndVerifyCPacket() throws Exception {
|
||||
// 测试设置新身份为当前身份
|
||||
KeyChain keyChain = new KeyChain();
|
||||
// Identity id = createRandomIdentity();
|
||||
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// 输入密码用于解锁身份
|
||||
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
private static Data createData(byte[] payload) throws ComponentException {
|
||||
Data data = new Data();
|
||||
data.freshnessPeriod.setFreshnessPeriod(02346345465453L);
|
||||
data.payload.setValue(payload);
|
||||
data.congestionMark.setCongestionLevel(1234L);
|
||||
Identifier id2 = new Identifier("/wzq");
|
||||
data.setName(id2);
|
||||
data.minPacket.packetType = new VlInt(3);
|
||||
return data;
|
||||
}
|
||||
|
||||
// 身份允许签名与验证签名
|
||||
private static CPacket createCPacket(byte[] payload) throws ComponentException {
|
||||
Identifier id1 = new Identifier("/min/pku/sz");
|
||||
Identifier id2 = new Identifier("/install");
|
||||
|
||||
@@ -128,47 +134,189 @@ public class KeychainBenchmark {
|
||||
cPacket.setSrcIdentifier(id1);
|
||||
cPacket.setDstIdentifier(id2);
|
||||
cPacket.setTtl(new TTL(16546418374324163L));
|
||||
cPacket.payload.setValue(new byte[]{1, 2, 3, 4, 6});
|
||||
cPacket.payload.setValue(payload);
|
||||
return cPacket;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
chain = new KeyChain();
|
||||
byte[] payLoad = createPayload(0);
|
||||
byte[] payLoad1K = createPayload(1);
|
||||
byte[] payLoad8K = createPayload(8);
|
||||
|
||||
// 1byte 兴趣包准备
|
||||
interest = createInterest(payLoad);
|
||||
interest2 = createInterest(payLoad);
|
||||
chain.signInterest(interest2);
|
||||
|
||||
// 1K 兴趣包准备
|
||||
interest3 = createInterest(payLoad1K);
|
||||
interest4 = createInterest(payLoad1K);
|
||||
chain.signInterest(interest4);
|
||||
|
||||
// 8K 兴趣包准备
|
||||
interest5 = createInterest(payLoad8K);
|
||||
interest6 = createInterest(payLoad8K);
|
||||
chain.signInterest(interest6);
|
||||
|
||||
// 1byte 数据包准备
|
||||
data = createData(payLoad);
|
||||
data2 = createData(payLoad);
|
||||
chain.signData(data2);
|
||||
|
||||
// 1K 数据包准备
|
||||
data3 = createData(payLoad1K);
|
||||
data4 = createData(payLoad1K);
|
||||
chain.signData(data4);
|
||||
|
||||
// 8K 数据包准备
|
||||
data5 = createData(payLoad8K);
|
||||
data6 = createData(payLoad8K);
|
||||
chain.signData(data6);
|
||||
|
||||
// 1byte 普通包准备
|
||||
cPacket = createCPacket(payLoad);
|
||||
cPacket2 = createCPacket(payLoad);
|
||||
chain.signCPacket(cPacket2);
|
||||
|
||||
// 1K 普通包准备
|
||||
cPacket3 = createCPacket(payLoad1K);
|
||||
cPacket4 = createCPacket(payLoad1K);
|
||||
chain.signCPacket(cPacket4);
|
||||
|
||||
// 8K 普通包准备
|
||||
cPacket5 = createCPacket(payLoad8K);
|
||||
cPacket6 = createCPacket(payLoad8K);
|
||||
chain.signCPacket(cPacket6);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// @Benchmark
|
||||
// public void testCreateKeyChain() throws Exception {
|
||||
// KeyChain keyChain = new KeyChain();
|
||||
// }
|
||||
//
|
||||
// @Benchmark
|
||||
// public void testInitialKeyChain() throws Exception {
|
||||
// // 测试设置新身份为当前身份
|
||||
// KeyChain keyChain = new KeyChain();
|
||||
// // Identity id = createRandomIdentity();
|
||||
// // keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// // 输入密码用于解锁身份
|
||||
// // keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
// }
|
||||
|
||||
@Benchmark
|
||||
public void testSignData() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
keyChain.signCPacket(cPacket);
|
||||
keyChain.verifyCPacket(cPacket);
|
||||
chain.signData(data);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignAndVerifyData() throws Exception {
|
||||
// 测试设置新身份为当前身份
|
||||
KeyChain keyChain = new KeyChain();
|
||||
// Identity id = createRandomIdentity();
|
||||
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// 输入密码用于解锁身份
|
||||
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
//////////////////// 构建Data包 ////////////////////////
|
||||
Data data = new Data();
|
||||
data.freshnessPeriod.setFreshnessPeriod(02346345465453L);
|
||||
data.payload.setValue(new byte[]{1, 2, 3, 4, 5});
|
||||
data.congestionMark.setCongestionLevel(1234L);
|
||||
Identifier id2 = new Identifier("/wzq");
|
||||
data.setName(id2);
|
||||
data.minPacket.packetType = new VlInt(3);
|
||||
public void testSignData1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
keyChain.signData(data);
|
||||
keyChain.verifyData(data);
|
||||
chain.signData(data3);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testExportAndImportSafeBag() throws Exception {
|
||||
// 测试设置新身份为当前身份
|
||||
KeyChain keyChain = new KeyChain();
|
||||
// Identity id = createRandomIdentity();
|
||||
// keyChain.getIdentifyManager().setDefaultIdentity(id, true);
|
||||
// 输入密码用于解锁身份
|
||||
// keyChain.setCurrentIdentity(keyChain.getIdentifyManager().getDefaultIdentity(), "0123456789abcdef");
|
||||
// 正常导入导出 通过
|
||||
Identity id2 = createRandomIdentity();
|
||||
SafeBag bag = keyChain.exportSafeBag(id2, "1234");
|
||||
keyChain.importSafeBag(bag, "1234", true);
|
||||
public void testSignData8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signData(data5);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyData() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyData(data2);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyData1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyData(data4);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyData8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyData(data6);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignCPacket() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signCPacket(cPacket);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignCPacket1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signCPacket(cPacket3);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignCPacket8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signCPacket(cPacket5);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyCPacket() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyCPacket(cPacket2);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyCPacket1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyCPacket(cPacket4);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyCPacket8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyCPacket(cPacket6);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignInterest() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signInterest(interest);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignInterest1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signInterest(interest3);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testSignInterest8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.signInterest(interest5);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyInterest() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyInterest(interest2);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyInterest1K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyInterest(interest4);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testVerifyInterest8K() throws Exception {
|
||||
// 正常测试签名与验签
|
||||
chain.verifyInterest(interest6);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(KeychainBenchmark.class.getSimpleName())
|
||||
|
||||
Reference in New Issue
Block a user