[][openwrt][common][Add SEJ test to script]

[Description]
Add SEJ test to script

Use `python3 main.py -a CBC -e sej` and
`python3 main.py -a CBC -e sej -m` to test SEJ CBC mode
Use `python3 main.py -a ECB -e sej` and
`python3 main.py -a ECB -e sej -m` to test SEJ ECB mode

[Release-log]

Change-Id: I8dc24c1d9f7410686b3a0558d3215e169d929fa3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8573939
diff --git a/feed/app/fips_test_tool/files/root/fips_test_tool/algo.py b/feed/app/fips_test_tool/files/root/fips_test_tool/algo.py
index 02f3b03..d33355e 100644
--- a/feed/app/fips_test_tool/files/root/fips_test_tool/algo.py
+++ b/feed/app/fips_test_tool/files/root/fips_test_tool/algo.py
@@ -84,6 +84,9 @@
                     result = self.sw_command(suites, test, algo)
                 elif self.engine == "hw":
                     result = self.hw_command(suites, test, algo)
+                else:
+                    print("No this engine")
+                    exit()
 
                 expect = self.get_expect(test)
 
diff --git a/feed/app/fips_test_tool/files/root/fips_test_tool/cbc.py b/feed/app/fips_test_tool/files/root/fips_test_tool/cbc.py
index 7cf1156..b2821e2 100644
--- a/feed/app/fips_test_tool/files/root/fips_test_tool/cbc.py
+++ b/feed/app/fips_test_tool/files/root/fips_test_tool/cbc.py
@@ -89,6 +89,21 @@
 
         return result.replace("\n", "").replace(" ", "")
 
+    def sej_command(self, suite, test, algo):
+        data = ""
+        mode = ""
+
+        if self.mode == "ENCRYPT":
+            data = test['PLAINTEXT']
+            mode = "enc"
+        elif self.mode == 'DECRYPT':
+            data = test['CIPHERTEXT']
+            mode = "dec"
+        command = "crypto_test " + mode + " cbc -k " + test['KEY'] + \
+                  " -i "+ test['IV']+ " " + data
+        result = os.popen(command).read().replace(" ", "")
+        return result.replace("\n", "").replace(" ", "")
+
     def select_algo(self, suites):
         algo = "none"
         if suites['keylen'] == '128':
@@ -135,6 +150,9 @@
                     result = self.sw_command(suite, test, algo)
                 elif self.engine == "hw":
                     result = self.hw_command(suite, test, algo)
+                elif self.engine == "sej":
+                    result = self.sej_command(suite, test, algo)
+
 
                 if(self.mode == 'ENCRYPT'):
                     if(i == 0):
@@ -166,3 +184,31 @@
                 return False
                 break
         return True
+
+    def run_command(self):
+        result = ""
+        expect = ""
+        pass_count = 0
+        total = 0
+
+        for suites in self.test_suites:
+            count = 0
+            algo = self.select_algo(suites)
+            if(algo == "none"):
+                continue
+
+            for test in suites['Tests']:
+                if self.engine == "sw":
+                    result = self.sw_command(suites, test, algo)
+                elif self.engine == "hw":
+                    result = self.hw_command(suites, test, algo)
+                elif self.engine == "sej":
+                    result = self.sej_command(suites, test, algo)
+
+                expect = self.get_expect(test)
+
+                if(result == expect):
+                    pass_count = pass_count + 1
+                    count = count + 1
+            total = total + len(suites['Tests'])
+        print("\t\t\ttotal case: %d, pass case: %d, rate: %f" %(total, pass_count, pass_count/total))
diff --git a/feed/app/fips_test_tool/files/root/fips_test_tool/ecb.py b/feed/app/fips_test_tool/files/root/fips_test_tool/ecb.py
index fc4e8b8..2e0595c 100644
--- a/feed/app/fips_test_tool/files/root/fips_test_tool/ecb.py
+++ b/feed/app/fips_test_tool/files/root/fips_test_tool/ecb.py
@@ -89,6 +89,21 @@
         result = os.popen(command).read().replace(" ", "")
         return result.replace("\n", "").replace(" ", "")
 
+    def sej_command(self, suite, test, algo):
+        data = ""
+        mode = ""
+
+        if self.mode == "ENCRYPT":
+            data = test['PLAINTEXT']
+            mode = "enc"
+        elif self.mode == 'DECRYPT':
+            data = test['CIPHERTEXT']
+            mode = "dec"
+        command = "crypto_test " + mode + " ecb -k " + test['KEY'] + \
+                  " " + data
+        result = os.popen(command).read().replace(" ", "")
+        return result.replace("\n", "").replace(" ", "")
+
     def select_algo(self, suites):
         algo = "none"
         if suites['keylen'] == '128':
@@ -128,6 +143,8 @@
                     result = self.sw_command(suite, test, algo)
                 elif self.engine == "hw":
                     result = self.hw_command(suite, test, algo)
+                elif self.engine == "sej":
+                    result = self.sej_command(suite, test, algo)
 
                 if(self.mode == 'ENCRYPT'):
                     data = result.replace("\n", "")
@@ -142,3 +159,31 @@
                 return False
                 break
         return True
+
+    def run_command(self):
+        result = ""
+        expect = ""
+        pass_count = 0
+        total = 0
+
+        for suites in self.test_suites:
+            count = 0
+            algo = self.select_algo(suites)
+            if(algo == "none"):
+                continue
+
+            for test in suites['Tests']:
+                if self.engine == "sw":
+                    result = self.sw_command(suites, test, algo)
+                elif self.engine == "hw":
+                    result = self.hw_command(suites, test, algo)
+                elif self.engine == "sej":
+                    result = self.sej_command(suites, test, algo)
+
+                expect = self.get_expect(test)
+
+                if(result == expect):
+                    pass_count = pass_count + 1
+                    count = count + 1
+            total = total + len(suites['Tests'])
+        print("\t\t\ttotal case: %d, pass case: %d, rate: %f" %(total, pass_count, pass_count/total))
diff --git a/feed/app/fips_test_tool/files/root/fips_test_tool/main.py b/feed/app/fips_test_tool/files/root/fips_test_tool/main.py
index 2ccc069..dde5703 100644
--- a/feed/app/fips_test_tool/files/root/fips_test_tool/main.py
+++ b/feed/app/fips_test_tool/files/root/fips_test_tool/main.py
@@ -25,9 +25,13 @@
 def print_list():
     print("List all test command")
     print("\tpython3 main.py -a CBC -e hw        => Test CBC in hw mode")
+    print("\tpython3 main.py -a CBC -e sej       => Test CBC in sej mode")
     print("\tpython3 main.py -a CBC -e hw -m     => Test CBC Monte in hw mode")
+    print("\tpython3 main.py -a CBC -e sej -m    => Test CBC Monte in sej mode")
     print("\tpython3 main.py -a ECB -e hw        => Test EBC in hw mode")
+    print("\tpython3 main.py -a ECB -e sej       => Test EBC in sej mode")
     print("\tpython3 main.py -a ECB -e hw -m     => Test EBC Monte in hw mode")
+    print("\tpython3 main.py -a ECB -e sej -m    => Test EBC Monte in sej mode")
     print("\tpython3 main.py -a CCM -e hw        => Test CCM in hw mode")
     print("\tpython3 main.py -a GCM -e hw        => Test GCM in hw mode")
     print("\tpython3 main.py -a DRBG -e sw       => Test DRBG in sw mode")
@@ -45,7 +49,7 @@
     parser = argparse.ArgumentParser(description="FIPS Test Script")
     parser.add_argument("-a", "--algo", choices=["CBC", "ECB", "CCM", "GCM", "DRBG", "HMAC", "SHA", "TDES"], help="Algorithm to test")
     parser.add_argument("-m", action="store_true", help="Enable Monte test, only use in CBC, EBC, SHA and TDES")
-    parser.add_argument("-e", "--engine", choices=["sw", "hw"],help="Select hw or sw")
+    parser.add_argument("-e", "--engine", choices=["sw", "hw", "sej"],help="Select hw or sw")
     parser.add_argument("-l", action="store_true", help="List all test algo and mode")
 
     return parser.parse_args()