8 #include <mxhw_crypto_wrapper.h>
14 BIO_snprintf(char *buf
, size_t size
, const char *format
, ...){return 0;}
16 static double timeSWT
[16],timeHWU
[16],timeHWS
[16];
19 fill_data(u_char
*buf
, u_int size
)
31 size
= 160+((rand()%(MAX_BUF
-160))&0xfffffff0);
33 for(i
=0; i
<size
;i
++,p
++)
41 times_reset(u_int numPktSizes
)
43 memset(timeSWT
, 0, 16*sizeof(unsigned int));
44 memset(timeHWU
, 0, 16*sizeof(unsigned int));
45 memset(timeHWS
, 0, 16*sizeof(unsigned int));
48 unsigned int ixOsServTimestampGet(void);
54 return ixOsServTimestampGet();
61 timeswhw(double *swT
, double *hwT
, int idx
)
68 timereport(char *name
, u_int
*pktSizes
, u_int max
, u_int numPkt
, u_int total
)
76 PTIME("\n%ld/%ld\t%s*\t%s\t(M)\t(M)\tRATE\t%s*K\n",numPkt
, total
,name
, name
, name
);
77 for(m
=0; m
< max
; m
++)
79 bytes
= (double) pktSizes
[m
]*numPkt
/1e6
;
81 PTIME("%d\t%.2lf\t%.2lf\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n",
82 pktSizes
[m
], /* # of packets */
83 timeHWU
[m
], /* hw total time */
84 timeSWT
[m
], /* hw system time */
85 (timeHWU
[m
]!=0)? bytes
/timeHWU
[m
]:0, /* hw in M bytes */
86 (timeSWT
[m
]!=0)? bytes
/timeSWT
[m
]:0, /* sw in M bytes */
87 (timeHWU
[m
]!=0)? timeSWT
[m
]/timeHWU
[m
]:0, /* rate */
93 timestick(unsigned int end
, unsigned int start
)
95 return (end
<start
)? (0xffffffff-start
+end
+1):(end
-start
);
99 timeit(u_int hwsw
, u_int idx
, int type
, int add
)
101 static struct tms tstart
, tend
;
119 d
= (double) timestick(e
, s
)/sysconf(_SC_CLK_TCK
);
127 d
= (double) timestick(e
, s
)/sysconf(_SC_CLK_TCK
);
132 d
= (double) timestick(tend
.tms_stime
,tstart
.tms_stime
)/sysconf(_SC_CLK_TCK
);
142 test_set_keys(TESTHW
*t
, u_char
*keys
, int IS_AES
)
146 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
147 if (AES_set_encrypt_key(keys
, t
->klen
<<3, &t
->AESKey1
) ||
148 AES_set_decrypt_key(keys
, t
->klen
<<3, &t
->AESKey2
))
150 t
->key1
= &t
->AESKey1
;
151 t
->key2
= &t
->AESKey2
;
157 DES_set_key_unchecked((DES_cblock
*) keys
, &t
->DESks1
);
158 DES_set_key_unchecked((DES_cblock
*) (keys
+8), &t
->DESks2
);
159 DES_set_key_unchecked((DES_cblock
*) (keys
+16), &t
->DESks3
);
160 t
->key1
= &t
->DESks1
;
161 t
->key2
= &t
->DESks2
;
162 t
->key3
= &t
->DESks3
;
166 TCIPHER(test_DES_ecb_encrypt
)
168 if (length
< HWACC_PKTLEN_MIN_DES
|| mxcrypto_perfrom(MXCIPHER_ALGO_DES
, MXCIPHER_MODE_ECB
,
169 (const u_char
*) input
, output
, length
, ks1
, NULL
, NULL
, NULL
,0, enc
))
174 DES_ecb_encrypt((const_DES_cblock
*) (input
+len
),(DES_cblock
*)(output
+len
),
175 (DES_key_schedule
*) ks1
,enc
);
181 TCIPHER(test_DES_cbc_encrypt
)
183 DES_ncbc_encrypt(input
,output
, length
,(DES_key_schedule
*)ks1
,(DES_cblock
*)ivec
, enc
);
187 TCIPHER(test_DES_cfb_encrypt
)
189 DES_cfb_encrypt(input
,output
,8,length
,(DES_key_schedule
*)ks1
,(DES_cblock
*)ivec
, enc
);
192 TCIPHER(test_DES_ofb_encrypt
)
195 DES_ofb64_encrypt(input
,output
,length
,(DES_key_schedule
*)ks1
,(DES_cblock
*)ivec
, &blks
);
198 /* not supported by CPE */
199 TCIPHER(test_DES_cfb64_encrypt
)
202 DES_cfb64_encrypt(input
,output
,length
,(DES_key_schedule
*)ks1
,(DES_cblock
*)ivec
, &blks
, enc
);
207 TCIPHER(test_DES_ecb3_encrypt
)
209 if (length
< HWACC_PKTLEN_MIN
|| mxcrypto_perfrom(MXCIPHER_ALGO_3DES
, MXCIPHER_MODE_ECB
,
210 (const u_char
*) input
, output
, length
, ks1
, ks2
, ks3
, NULL
,0, enc
))
216 DES_ecb3_encrypt(input
+len
, output
+len
,
217 (DES_key_schedule
*)ks1
, (DES_key_schedule
*)ks2
, (DES_key_schedule
*)ks3
, enc
);
223 TCIPHER(test_DES_ede3_cbc_encrypt
)
225 DES_ede3_cbc_encrypt(input
, output
, length
,
226 (DES_key_schedule
*)ks1
, (DES_key_schedule
*)ks2
, (DES_key_schedule
*)ks3
, (DES_cblock
*)ivec
, enc
);
230 TCIPHER(test_DES_ede3_ofb64_encrypt
)
233 DES_ede3_ofb64_encrypt(input
, output
, length
,
234 (DES_key_schedule
*)ks1
, (DES_key_schedule
*)ks2
, (DES_key_schedule
*)ks3
, (DES_cblock
*)ivec
, &blks
);
237 TCIPHER(test_DES_ede3_cfb64_encrypt
)
239 DES_ede3_cfb_encrypt(input
, output
, 8, length
,
240 (DES_key_schedule
*)ks1
, (DES_key_schedule
*)ks2
, (DES_key_schedule
*)ks3
, (DES_cblock
*)ivec
, enc
);
244 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
245 TCIPHER(test_AES_ecb_encrypt
)
247 if (length
< HWACC_PKTLEN_MIN
|| mxcrypto_perfrom(MXCIPHER_ALGO_AES
, MXCIPHER_MODE_ECB
,
248 (const u_char
*) input
, output
, length
, ks1
, NULL
, NULL
, NULL
, 0, enc
)!=0)
253 AES_ecb_encrypt(input
+len
, output
+len
, (const AES_KEY
*) (enc
? ks1
:ks2
), enc
);
259 TCIPHER(test_AES_cbc_encrypt
)
261 AES_cbc_encrypt(input
, output
, length
, (const AES_KEY
*) (enc
? ks1
:ks2
), ivec
, enc
);
264 TCIPHER(test_AES_ctr_encrypt
)
266 unsigned char ctr
[AES_BLOCK_SIZE
];
269 memset(ctr
, 0, AES_BLOCK_SIZE
);
270 AES_ctr128_encrypt(input
, output
, length
, (const AES_KEY
*) ks1
, ivec
, ctr
, &blks
);
274 TCIPHER(test_AES_cfb_encrypt
)
277 AES_cfb8_encrypt(input
, output
, length
, (const AES_KEY
*) ks1
, ivec
, &blks
, enc
);
280 TCIPHER(test_AES_cfb128_encrypt
)
283 AES_cfb128_encrypt(input
, output
, length
, (const AES_KEY
*) ks1
, ivec
, &blks
, enc
);
286 TCIPHER(test_AES_ofb_encrypt
)
289 AES_ofb128_encrypt(input
, output
, length
, (const AES_KEY
*) ks1
, ivec
, &blks
);