Path: blob/main/crypto/libecc/scripts/test_ec_utils.sh
34858 views
#/*1# * Copyright (C) 2021 - This file is part of libecc project2# *3# * Authors:4# * Ryad BENADJILA <[email protected]>5# * Arnaud EBALARD <[email protected]>6# *7# * This software is licensed under a dual BSD and GPL v2 license.8# * See LICENSE file at the root folder of the project.9# */10#!/bin/bash1112BASEDIR=$(dirname "$0")13EC_UTILS=$BASEDIR/../build/ec_utils1415# trap ctrl-c and call ctrl_c()16trap ctrl_c INT1718function ctrl_c() {19echo "** Trapped CTRL-C, cleaning ..."20rm -f test_key_public_key.bin test_key_private_key.bin test_key_private_key.h test_key_public_key.h signed_file.bin.signed21exit22}2324# Test ec_utils cases25curves=("FRP256V1" "SECP192R1" "SECP224R1" "SECP256R1" "SECP384R1" "SECP521R1" "BRAINPOOLP192R1" "BRAINPOOLP224R1" "BRAINPOOLP256R1" "BRAINPOOLP384R1" "BRAINPOOLP512R1" "GOST256" "GOST512" "SM2P256TEST" "SM2P256V1" "WEI25519" "WEI448" "GOST_R3410_2012_256_PARAMSETA" "SECP256K1")26signatures=("ECDSA" "ECKCDSA" "ECSDSA" "ECOSDSA" "ECFSDSA" "ECGDSA" "ECRDSA" "SM2" "EDDSA25519" "EDDSA25519CTX" "EDDSA25519PH" "EDDSA448" "EDDSA448PH" "DECDSA")27hashes=("SHA224" "SHA256" "SHA384" "SHA512" "SHA512_224" "SHA512_256" "SHA3_224" "SHA3_256" "SHA3_384" "SHA3_512" "SM3" "SHAKE256" "STREEBOG256" "STREEBOG512")2829for c in "${!curves[@]}"30do31for s in "${!signatures[@]}"32do33# Generate keys34# NOTE: EDDSA family only accepts WEI curves35if [[ "${signatures[s]}" == "EDDSA25519" || "${signatures[s]}" == "EDDSA25519CTX" || "${signatures[s]}" == "EDDSA25519PH" ]]36then37if [[ "${curves[c]}" != "WEI25519" ]]38then39continue40fi41fi42if [[ "${signatures[s]}" == "EDDSA448" || "${signatures[s]}" == "EDDSA448PH" ]]43then44if [[ "${curves[c]}" != "WEI448" ]]45then46continue47fi48fi49echo "===== ${curves[c]} ${signatures[s]}"50$EC_UTILS gen_keys ${curves[c]} ${signatures[s]} test_key || exit 051for h in "${!hashes[@]}"52do53if [[ "${signatures[s]}" == "EDDSA25519" || "${signatures[s]}" == "EDDSA25519CTX" || "${signatures[s]}" == "EDDSA25519PH" ]]54then55if [[ "${hashes[h]}" != "SHA512" ]]56then57continue58fi59fi60if [[ "${signatures[s]}" == "EDDSA448" || "${signatures[s]}" == "EDDSA448PH" ]]61then62if [[ "${hashes[h]}" != "SHAKE256" ]]63then64continue65fi66fi67echo "========= TESTING ${curves[c]} ${signatures[s]} ${hashes[h]}"68# Try to sign69$EC_UTILS sign ${curves[c]} ${signatures[s]} ${hashes[h]} $EC_UTILS test_key_private_key.bin signed_file.bin.signed "ANCILLARY" || exit 070# Try to verify71$EC_UTILS verify ${curves[c]} ${signatures[s]} ${hashes[h]} $EC_UTILS test_key_public_key.bin signed_file.bin.signed "ANCILLARY" || exit 072rm -f signed_file.bin.signed73# Try to "struct" sign74$EC_UTILS struct_sign ${curves[c]} ${signatures[s]} ${hashes[h]} $EC_UTILS test_key_private_key.bin signed_file.bin.signed IMAGE_TYPE0 1337 "ANCILLARY" || exit 075# Try to "struct" verify76$EC_UTILS struct_verify ${curves[c]} ${signatures[s]} ${hashes[h]} signed_file.bin.signed test_key_public_key.bin "ANCILLARY" || exit 077rm -f signed_file.bin.signed78done79rm -f test_key_public_key.bin test_key_private_key.bin test_key_private_key.h test_key_public_key.h80done81done828384