aboutsummaryrefslogtreecommitdiffstats
path: root/test/crypto/ref
diff options
context:
space:
mode:
authorareviu <areviu.info@gmail.com>2017-11-13 20:31:01 +0000
committerareviu <areviu.info@gmail.com>2017-11-13 20:31:01 +0000
commitabc49200f7cdd8b9698e767cec7df95a4ec039e2 (patch)
tree9e412a5a8bb4362bf237c935c142806dd662ed22 /test/crypto/ref
parent6345e21b5deb23408ef15574904b12df329fa9fe (diff)
downloadChibiOS-abc49200f7cdd8b9698e767cec7df95a4ec039e2.tar.gz
ChibiOS-abc49200f7cdd8b9698e767cec7df95a4ec039e2.tar.bz2
ChibiOS-abc49200f7cdd8b9698e767cec7df95a4ec039e2.zip
added aes and (t)des in dma mode + test suite crypto
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10993 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test/crypto/ref')
-rw-r--r--test/crypto/ref/README.txt2
-rw-r--r--test/crypto/ref/aes_ref.bat17
-rw-r--r--test/crypto/ref/des_ref.bat8
-rw-r--r--test/crypto/ref/gen_cfiles.bat4
-rw-r--r--test/crypto/ref/gen_testref.bat12
-rw-r--r--test/crypto/ref/genfile.py68
-rw-r--r--test/crypto/ref/ref_data.bat7
-rw-r--r--test/crypto/ref/setpath.bat2
8 files changed, 120 insertions, 0 deletions
diff --git a/test/crypto/ref/README.txt b/test/crypto/ref/README.txt
new file mode 100644
index 000000000..6df947b08
--- /dev/null
+++ b/test/crypto/ref/README.txt
@@ -0,0 +1,2 @@
+set path of python and openssl in setpath.bat
+launch gen_testref.bat \ No newline at end of file
diff --git a/test/crypto/ref/aes_ref.bat b/test/crypto/ref/aes_ref.bat
new file mode 100644
index 000000000..05c132c08
--- /dev/null
+++ b/test/crypto/ref/aes_ref.bat
@@ -0,0 +1,17 @@
+
+
+%OPENSSL%\openssl enc -aes-128-ecb -nosalt -nopad -K %K16% -in plaintext -out aes_ecb_128.enc
+%OPENSSL%\openssl enc -aes-192-ecb -nopad -nosalt -K %K24% -in plaintext -out aes_ecb_192.enc
+%OPENSSL%\openssl enc -aes-256-ecb -nopad -nosalt -K %K32% -in plaintext -out aes_ecb_256.enc
+
+%OPENSSL%\openssl enc -aes-128-cbc -nopad -nosalt -K %K16% -iv %IV% -in plaintext -out aes_cbc_128.enc
+%OPENSSL%\openssl enc -aes-192-cbc -nopad -nosalt -K %K24% -iv %IV% -in plaintext -out aes_cbc_192.enc
+%OPENSSL%\openssl enc -aes-256-cbc -nopad -nosalt -K %K32% -iv %IV% -in plaintext -out aes_cbc_256.enc
+
+%OPENSSL%\openssl enc -aes-128-ctr -nopad -nosalt -K %K16% -iv %IV% -in plaintext -out aes_ctr_128.enc
+%OPENSSL%\openssl enc -aes-192-ctr -nopad -nosalt -K %K24% -iv %IV% -in plaintext -out aes_ctr_192.enc
+%OPENSSL%\openssl enc -aes-256-ctr -nopad -nosalt -K %K32% -iv %IV% -in plaintext -out aes_ctr_256.enc
+
+%OPENSSL%\openssl enc -aes-128-cfb -nopad -nosalt -K %K16% -iv %IV% -in plaintext -out aes_cfb_128.enc
+%OPENSSL%\openssl enc -aes-192-cfb -nopad -nosalt -K %K24% -iv %IV% -in plaintext -out aes_cfb_192.enc
+%OPENSSL%\openssl enc -aes-256-cfb -nopad -nosalt -K %K32% -iv %IV% -in plaintext -out aes_cfb_256.enc
diff --git a/test/crypto/ref/des_ref.bat b/test/crypto/ref/des_ref.bat
new file mode 100644
index 000000000..62d031391
--- /dev/null
+++ b/test/crypto/ref/des_ref.bat
@@ -0,0 +1,8 @@
+
+call %OPENSSL%\openssl enc -des-ecb -nopad -nosalt -K %K8% -e -in plaintext -out des_ecb_8.enc
+
+REM TDES
+call %OPENSSL%\openssl enc -des-ede-ecb -nopad -nosalt -K %K16% -e -in plaintext -out tdes_ecb_16.enc
+call %OPENSSL%\openssl enc -des-ede3-ecb -nopad -nosalt -K %K24% -e -in plaintext -out tdes_ecb_24.enc
+call %OPENSSL%\openssl enc -des-ede-cbc -nopad -nosalt -K %K16% -iv %DES_IV% -e -in plaintext -out tdes_cbc_16.enc
+call %OPENSSL%\openssl enc -des-ede3-cbc -nopad -nosalt -K %K24% -iv %DES_IV% -e -in plaintext -out tdes_cbc_24.enc \ No newline at end of file
diff --git a/test/crypto/ref/gen_cfiles.bat b/test/crypto/ref/gen_cfiles.bat
new file mode 100644
index 000000000..d0bc19ff9
--- /dev/null
+++ b/test/crypto/ref/gen_cfiles.bat
@@ -0,0 +1,4 @@
+%PYTHON%\python genfile.py -f aes_ecb_128,aes_ecb_192,aes_ecb_256,aes_cbc_128,aes_cbc_192,aes_cbc_256,aes_ctr_128,aes_ctr_192,aes_ctr_256,aes_cfb_128,aes_cfb_192,aes_cfb_256 -o ref_aes -p ../source/testref
+
+%PYTHON%\python genfile.py -f des_ecb_8,tdes_ecb_16,tdes_ecb_24,tdes_cbc_16,tdes_cbc_24 -o ref_des -p ../source/testref
+
diff --git a/test/crypto/ref/gen_testref.bat b/test/crypto/ref/gen_testref.bat
new file mode 100644
index 000000000..311376773
--- /dev/null
+++ b/test/crypto/ref/gen_testref.bat
@@ -0,0 +1,12 @@
+call setpath.bat
+
+call ref_data.bat
+
+del *.enc
+
+%PYTHON%\python -c "print 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent et pellentesque risus. Sed id gravida elit. Proin eget accumsan mi. Aliquam vitae dui porta, euismod velit viverra, elementum lacus. Nunc turpis orci, venenatis vel vulputate nec, luctus sitamet urna. Ut et nunc purus. Aliquam erat volutpat. Vestibulum nulla dolor, cursus vitae cursus eget, dapibus eget sapien. Integer justo eros, commodo ut massa eu, bibendum elementum tellus. Nam quis dolor in libero placerat congue. Sed sodales urna scelerisque dui faucibus, vitae malesuada dui fermentum. Proin ultricies sit amet justo at ornare. Suspendisse efficitur purus nullam.'.decode('ascii')" > plaintext
+
+call aes_ref.bat
+call des_ref.bat
+
+call gen_cfiles.bat \ No newline at end of file
diff --git a/test/crypto/ref/genfile.py b/test/crypto/ref/genfile.py
new file mode 100644
index 000000000..4bfac9e12
--- /dev/null
+++ b/test/crypto/ref/genfile.py
@@ -0,0 +1,68 @@
+import sys,getopt,string
+
+filenames = None
+fileOut = None
+filePath = None
+blocksize = 1024
+i = 0
+
+license ='/*\n'\
+' ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio\n'\
+'\n'\
+' Licensed under the Apache License, Version 2.0 (the "License");\n'\
+' you may not use this file except in compliance with the License.\n'\
+' You may obtain a copy of the License at\n'\
+'\n'\
+' http://www.apache.org/licenses/LICENSE-2.0\n'\
+'\n'\
+' Unless required by applicable law or agreed to in writing, software\n'\
+' distributed under the License is distributed on an "AS IS" BASIS,\n'\
+' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'\
+' See the License for the specific language governing permissions and\n'\
+' limitations under the License.\n'\
+'*/\n'
+
+opts,args = getopt.getopt(sys.argv[1:],'f:o:p:')
+for o,a in opts:
+ if o == '-f':
+ filenames = a
+ if o == '-o':
+ fileOut = a
+ if o == '-p':
+ filePath = a
+
+
+filenames = filenames.split(",")
+
+fc = open (filePath+"/"+fileOut+".c","w")
+fh = open (filePath+"/"+fileOut+".h","w")
+fc.write(license)
+fc.write("\n#include \"hal.h\"\n\n")
+fh.write(license)
+fh.write("#ifndef TEST_"+fileOut.upper()+"_H_\n")
+fh.write("#define TEST_"+fileOut.upper()+"_H_\n\n")
+
+for fn in filenames:
+ print "opening ",fn
+ i = 0
+ f = open(fn+".enc","rb")
+ block = f.read(blocksize)
+ d = fn.split("_")
+
+
+
+ fc.write("const uint8_t ref"+d[0].upper()+"_"+d[1].upper()+"_"+d[2].upper()+"[]={\n")
+ fh.write("extern const uint8_t ref"+d[0].upper()+"_"+d[1].upper()+"_"+d[2].upper()+"[];\n")
+ str = ""
+ for ch in block:
+ i += 1
+ str += "0x"+format(ord(ch), '02X')+","
+ if i == 10:
+ str += "\n"
+ i = 0
+ fc.write(str)
+ fc.write("\n};\n")
+fh.write("#endif //TEST_"+fileOut.upper()+"_H_\n")
+
+
+
diff --git a/test/crypto/ref/ref_data.bat b/test/crypto/ref/ref_data.bat
new file mode 100644
index 000000000..9a9ccd362
--- /dev/null
+++ b/test/crypto/ref/ref_data.bat
@@ -0,0 +1,7 @@
+set K8=67452301EFCDAB89
+set K16=67452301EFCDAB891032547698BADCFE
+set K24=67452301EFCDAB891032547698BADCFEAA55AA5555AA55AA
+set K32=67452301EFCDAB891032547698BADCFEAA55AA5555AA55AAFFFF00000000FFFF
+set IV=44332211887766552222111144443333
+set DES_IV=4433221188776655
+
diff --git a/test/crypto/ref/setpath.bat b/test/crypto/ref/setpath.bat
new file mode 100644
index 000000000..196545e16
--- /dev/null
+++ b/test/crypto/ref/setpath.bat
@@ -0,0 +1,2 @@
+set PYTHON=E:\python\Python27
+set OPENSSL=E:\dev\OpenSSL-Win64\bin \ No newline at end of file