X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Ftest_cms.py;h=b289fa5595afb469e158646b8b3bc6343301ecc1;hb=2bb1a163d32e4167e6904ff3c6b4cf64ea7287bb;hp=a6f1ae6fd5c985c381249bb1c8ce4955bd19f1be;hpb=21a30721c31912c296e1faced73e2fd0db191be9;p=pygost.git diff --git a/pygost/test_cms.py b/pygost/test_cms.py index a6f1ae6..b289fa5 100644 --- a/pygost/test_cms.py +++ b/pygost/test_cms.py @@ -1,11 +1,10 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2019 Sergey Matveev +# Copyright (C) 2015-2020 Sergey Matveev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,8 +19,7 @@ from unittest import skipIf from unittest import TestCase from pygost.gost28147 import cfb_decrypt -from pygost.gost3410 import CURVE_PARAMS -from pygost.gost3410 import GOST3410Curve +from pygost.gost3410 import CURVES from pygost.gost3410 import prv_unmarshal from pygost.gost3410 import pub_unmarshal from pygost.gost3410 import public_key @@ -68,7 +66,7 @@ class TestSigned(TestCase): self.assertIsNotNone(content_info["content"].defined) _, signed_data = content_info["content"].defined self.assertEqual(len(signed_data["signerInfos"]), 1) - curve = GOST3410Curve(*CURVE_PARAMS[curve_name]) + curve = CURVES[curve_name] self.assertTrue(verify( curve, public_key(curve, prv_unmarshal(prv_key_raw)), @@ -90,7 +88,7 @@ VNwDQ8enFItJZ8DEX4blZ8QtziNCMl5HbA== self.process_cms( content_info_raw, prv_key_raw, - "GostR3410_2001_CryptoPro_XchA_ParamSet", + "id-GostR3410-2001-CryptoPro-XchA-ParamSet", GOST34112012256, 2001, ) @@ -109,7 +107,7 @@ PS+KRYxT8vhcsBLWWxDkc1McI7aF09hqtED36mQOfACzeJjEoUjALpmJob1V self.process_cms( content_info_raw, prv_key_raw, - "GostR3410_2012_TC26_ParamSetB", + "id-tc26-gost-3410-12-512-paramSetB", GOST34112012512, 2012, ) @@ -166,7 +164,7 @@ class TestEnvelopedKTRI(TestCase): keker, plaintext_expected, ): - sbox = "Gost28147_tc26_ParamZ" + sbox = "id-tc26-gost-28147-param-Z" content_info, tail = ContentInfo().decode(content_info_raw, ctx={ "defines_by_path": [ ( @@ -209,7 +207,7 @@ class TestEnvelopedKTRI(TestCase): spk = encrypted_key["transportParameters"]["ephemeralPublicKey"]["subjectPublicKey"] self.assertIsNotNone(spk.defined) _, pub_key_their = spk.defined - curve = GOST3410Curve(*CURVE_PARAMS[curve_name]) + curve = CURVES[curve_name] kek = keker(curve, prv_key_our, bytes(pub_key_their), ukm) key_wrapped = bytes(encrypted_key["sessionEncryptedKey"]["encryptedKey"]) mac = bytes(encrypted_key["sessionEncryptedKey"]["macKey"]) @@ -294,7 +292,7 @@ pRmMVN+YtRsrEHwH3ToQ/i4vrtgA+eONuKT2uKZFikxA+VNmeeGdhkgqETMihQ== self.process_cms( content_info_raw, prv_key_our, - "GostR3410_2001_CryptoPro_XchA_ParamSet", + "id-GostR3410-2001-CryptoPro-XchA-ParamSet", keker, b"Test data to encrypt.\n" * 100, ) @@ -325,7 +323,7 @@ FTAVBAj+1QzaXaN9FwYJKoUDBwECBQEBgAyK54euw0sHhEVEkA0= self.process_cms( content_info_raw, prv_key_our, - "GostR3410_2012_TC26_ParamSetB", + "id-tc26-gost-3410-12-512-paramSetB", keker, b"Test message", ) @@ -346,7 +344,7 @@ class TestEnvelopedKARI(TestCase): keker, plaintext_expected, ): - sbox = "Gost28147_tc26_ParamZ" + sbox = "id-tc26-gost-28147-param-Z" content_info, tail = ContentInfo().decode(content_info_raw, ctx={ "defines_by_path": [ ( @@ -370,7 +368,7 @@ class TestEnvelopedKARI(TestCase): }, ), ), - ) for spki_algorithm in ( + ) for _ in ( id_tc26_gost3410_2012_256, id_tc26_gost3410_2012_512, ) @@ -385,7 +383,7 @@ class TestEnvelopedKARI(TestCase): _, pub_key_their = kari["originator"]["originatorKey"]["publicKey"].defined ukm = bytes(kari["ukm"]) rek = kari["recipientEncryptedKeys"][0] - curve = GOST3410Curve(*CURVE_PARAMS[curve_name]) + curve = CURVES[curve_name] kek = keker(curve, prv_key_our, bytes(pub_key_their), ukm) self.assertIsNotNone(rek["encryptedKey"].defined) _, encrypted_key = rek["encryptedKey"].defined @@ -427,7 +425,7 @@ UNjyuY+54uVcHw== self.process_cms( content_info_raw, prv_key_our, - "GostR3410_2001_CryptoPro_XchA_ParamSet", + "id-GostR3410-2001-CryptoPro-XchA-ParamSet", keker, b"Test message", ) @@ -458,7 +456,7 @@ WFUZEnEuAKcuG6dTOawEBLhi9hIwOgYJKoZIhvcNAQcBMB8GBiqFAwICFTAVBAiD self.process_cms( content_info_raw, prv_key_our, - "GostR3410_2012_TC26_ParamSetB", + "id-tc26-gost-3410-12-512-paramSetB", keker, b"Test message", )