/ external / libecc / scripts / gen_openssl_curves_tests.sh
gen_openssl_curves_tests.sh
 1  #/*
 2  # *  Copyright (C) 2017 - This file is part of libecc project
 3  # *
 4  # *  Authors:
 5  # *      Ryad BENADJILA <ryadbenadjila@gmail.com>
 6  # *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
 7  # *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
 8  # *
 9  # *  Contributors:
10  # *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11  # *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12  # *
13  # *  This software is licensed under a dual BSD and GPL v2 license.
14  # *  See LICENSE file at the root folder of the project.
15  # */
16  #!/bin/sh
17  
18  CURVES=`openssl ecparam -list_curves | grep prime | cut -d':' -f1 | tr '\n' ' '`
19  
20  # Find a suitable python command if none has been provided
21  if [ -z "$PYTHON" ]
22  then
23          echo "Looking for suitable python and deps"
24          # Try to guess which python we want to use depending on the installed
25          # packages. We need Pyscard, Crypto, and IntelHex
26          for i in python python3 python2; do
27                  if [ -x "`which $i`" ]; then
28                          echo "Found and using python=$i"
29                          PYTHON=$i
30                          break
31                  fi
32          done
33  else
34          echo "Using user provided python=$PYTHON"
35  fi
36  
37  if [ -z "$PYTHON" ]; then
38          echo "Failed to find working python cmd!" >&2
39          exit
40  fi
41  
42  # Get the expand_libecc python script path
43  BASEDIR=$(dirname "$0")
44  EXPAND_LIBECC=$BASEDIR/expand_libecc.py
45  
46  for curve in $CURVES
47  do
48  	echo "Adding $curve"
49  	openssl ecparam -param_enc explicit -outform DER -name $curve -out "$curve".der
50  	$PYTHON $EXPAND_LIBECC --name="$curve" --ECfile="$curve".der --add-test-vectors=2
51  	rm "$curve".der
52  done