clear
? "生成一个长度"
begin:
dec_indent
total_len = random( 2 )
total_len = and( $total_len, 01ff )
if $total_len <= 30
goto begin
endif
? "生成一个数据"
data = hrandom( $total_len )
icv8 = hrandom( 08 )
icv16 = hrandom( 10 )
key8 = hrandom( 08 )
key16 = hrandom( 10 )
key24 = hrandom( 18 )
key32 = hrandom( 20 )
? "计算原始结果"
ori_des_res = des_cmac( $icv8, $data, $key8 )
ori_3des_res = 3des_cmac( $icv8, $data, $key16 )
ori_3des24_res = 3des24_cmac( $icv8, $data, $key24 )
ori_sm4_res = sm4_cmac( $icv16, $data, $key16 )
ori_aes128_res = aes128_cmac( $icv16, $data, $key16 )
ori_aes192_res = aes192_cmac( $icv16, $data, $key24 )
ori_aes256_res = aes256_cmac( $icv16, $data, $key32 )
? "使用循环,将data分成两段,做接力cmac计算"
off = 00
prompt off
while $off < $total_len
clear
data1 = hleft( $data, $off )
data2 = hmid( $data, $off )
call des_test
call 3des_test
call 3des24_test
call sm4_test
call aes128_test
call aes192_test
call aes256_test
off = add( $off, 01 )
loop
prompt on
end
des_test:
? "分两包分别update"
x = des_cmac_init( $key8, $icv8 )
x = des_cmac_update( $data1 )
x = des_cmac_update( $data2 )
x = des_cmac_final()
if $x != $ori_des_res
?
pause
endif
? "分两包,最后一包在final中update"
x = des_cmac_init( $key8, $icv8 )
x = des_cmac_update( $data1 )
x = des_cmac_final( $data2 )
if $x != $ori_des_res
?
pause
endif
? "分两包,使用中间值"
x = des_cmac_init( $key8, $icv8 )
tmp_icv = des_cmac_update( $data1 )
整包长度 = big_div( $off, 08 )
整包长度 = big_mul( $整包长度, 08 )
缓存长度 = big_mod( $off, 08 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 08
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = des_cmac_init( $key8, $icv8 )
x = des_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_des_res
?
pause
endif
? "重新初始化"
x = des_cmac_init( $key8, $icv8 )
x = des_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = des_cmac_final( $data2 )
if $x != $ori_des_res
?
pause
endif
return
3des_test:
? "分两包分别update"
x = 3des_cmac_init( $key16, $icv8 )
x = 3des_cmac_update( $data1 )
x = 3des_cmac_update( $data2 )
x = 3des_cmac_final()
if $x != $ori_3des_res
?
pause
endif
? "分两包,最后一包在final中update"
x = 3des_cmac_init( $key16, $icv8 )
x = 3des_cmac_update( $data1 )
x = 3des_cmac_final( $data2 )
if $x != $ori_3des_res
?
pause
endif
? "分两包,使用中间值"
x = 3des_cmac_init( $key16, $icv8 )
tmp_icv = 3des_cmac_update( $data1 )
整包长度 = big_div( $off, 08 )
整包长度 = big_mul( $整包长度, 08 )
缓存长度 = big_mod( $off, 08 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 08
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = 3des_cmac_init( $key16, $icv8 )
x = 3des_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_3des_res
?
pause
endif
? "重新初始化"
x = 3des_cmac_init( $key16, $icv8 )
x = 3des_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = 3des_cmac_final( $data2 )
if $x != $ori_3des_res
?
pause
endif
return
3des24_test:
? "分两包分别update"
x = 3des24_cmac_init( $key24, $icv8 )
x = 3des24_cmac_update( $data1 )
x = 3des24_cmac_update( $data2 )
x = 3des24_cmac_final()
if $x != $ori_3des24_res
?
pause
endif
? "分两包,最后一包在final中update"
x = 3des24_cmac_init( $key24, $icv8 )
x = 3des24_cmac_update( $data1 )
x = 3des24_cmac_final( $data2 )
if $x != $ori_3des24_res
?
pause
endif
? "分两包,使用中间值"
x = 3des24_cmac_init( $key24, $icv8 )
tmp_icv = 3des24_cmac_update( $data1 )
整包长度 = big_div( $off, 08 )
整包长度 = big_mul( $整包长度, 08 )
缓存长度 = big_mod( $off, 08 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 08
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = 3des24_cmac_init( $key24, $icv8 )
x = 3des24_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_3des24_res
?
pause
endif
? "重新初始化"
x = 3des24_cmac_init( $key24, $icv8 )
x = 3des24_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = 3des24_cmac_final( $data2 )
if $x != $ori_3des24_res
?
pause
endif
return
aes128_test:
? "分两包分别update"
x = aes128_cmac_init( $key16, $icv16 )
x = aes128_cmac_update( $data1 )
x = aes128_cmac_update( $data2 )
x = aes128_cmac_final()
if $x != $ori_aes128_res
?
pause
endif
? "分两包,最后一包在final中update"
x = aes128_cmac_init( $key16, $icv16 )
x = aes128_cmac_update( $data1 )
x = aes128_cmac_final( $data2 )
if $x != $ori_aes128_res
?
pause
endif
? "分两包,使用中间值"
x = aes128_cmac_init( $key16, $icv16 )
tmp_icv = aes128_cmac_update( $data1 )
整包长度 = big_div( $off, 10 )
整包长度 = big_mul( $整包长度, 10 )
缓存长度 = big_mod( $off, 10 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 10
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = aes128_cmac_init( $key16, $icv16 )
x = aes128_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_aes128_res
?
pause
endif
? "重新初始化"
x = aes128_cmac_init( $key16, $icv16 )
x = aes128_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = aes128_cmac_final( $data2 )
if $x != $ori_aes128_res
?
pause
endif
return
aes192_test:
? "分两包分别update"
x = aes192_cmac_init( $key24, $icv16 )
x = aes192_cmac_update( $data1 )
x = aes192_cmac_update( $data2 )
x = aes192_cmac_final()
if $x != $ori_aes192_res
?
pause
endif
? "分两包,最后一包在final中update"
x = aes192_cmac_init( $key24, $icv16 )
x = aes192_cmac_update( $data1 )
x = aes192_cmac_final( $data2 )
if $x != $ori_aes192_res
?
pause
endif
? "分两包,使用中间值"
x = aes192_cmac_init( $key24, $icv16 )
tmp_icv = aes192_cmac_update( $data1 )
整包长度 = big_div( $off, 10 )
整包长度 = big_mul( $整包长度, 10 )
缓存长度 = big_mod( $off, 10 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 10
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = aes192_cmac_init( $key24, $icv16 )
x = aes192_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_aes192_res
?
pause
endif
? "重新初始化"
x = aes192_cmac_init( $key24, $icv16 )
x = aes192_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = aes192_cmac_final( $data2 )
if $x != $ori_aes192_res
?
pause
endif
return
aes256_test:
? "分两包分别update"
x = aes256_cmac_init( $key32, $icv16 )
x = aes256_cmac_update( $data1 )
x = aes256_cmac_update( $data2 )
x = aes256_cmac_final()
if $x != $ori_aes256_res
?
pause
endif
? "分两包,最后一包在final中update"
x = aes256_cmac_init( $key32, $icv16 )
x = aes256_cmac_update( $data1 )
x = aes256_cmac_final( $data2 )
if $x != $ori_aes256_res
?
pause
endif
? "分两包,使用中间值"
x = aes256_cmac_init( $key32, $icv16 )
tmp_icv = aes256_cmac_update( $data1 )
整包长度 = big_div( $off, 10 )
整包长度 = big_mul( $整包长度, 10 )
缓存长度 = big_mod( $off, 10 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 10
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = aes256_cmac_init( $key32, $icv16 )
x = aes256_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_aes256_res
?
pause
endif
? "重新初始化"
x = aes256_cmac_init( $key32, $icv16 )
x = aes256_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = aes256_cmac_final( $data2 )
if $x != $ori_aes256_res
?
pause
endif
return
sm4_test:
? "分两包分别update"
x = sm4_cmac_init( $key16, $icv16 )
x = sm4_cmac_update( $data1 )
x = sm4_cmac_update( $data2 )
x = sm4_cmac_final()
if $x != $ori_sm4_res
?
pause
endif
? "分两包,最后一包在final中update"
x = sm4_cmac_init( $key16, $icv16 )
x = sm4_cmac_update( $data1 )
x = sm4_cmac_final( $data2 )
if $x != $ori_sm4_res
?
pause
endif
? "分两包,使用中间值"
x = sm4_cmac_init( $key16, $icv16 )
tmp_icv = sm4_cmac_update( $data1 )
整包长度 = big_div( $off, 10 )
整包长度 = big_mul( $整包长度, 10 )
缓存长度 = big_mod( $off, 10 )
if $缓存长度 == 00
// 这是因为最后一包只缓存,还没有参与计算
缓存长度 = 10
endif
缓存数据 = hright( $data1, $缓存长度 )
? "重新初始化"
x = sm4_cmac_init( $key16, $icv16 )
x = sm4_cmac_final( $data2, $tmp_icv, $整包长度, $缓存数据 )
if $x != $ori_sm4_res
?
pause
endif
? "重新初始化"
x = sm4_cmac_init( $key16, $icv16 )
x = sm4_cmac_update( , $tmp_icv, $整包长度, $缓存数据 )
x = sm4_cmac_final( $data2 )
if $x != $ori_sm4_res
?
pause
endif
return