# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
#
# 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
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
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)),
self.process_cms(
content_info_raw,
prv_key_raw,
- "GostR3410_2001_CryptoPro_XchA_ParamSet",
+ "id-GostR3410-2001-CryptoPro-XchA-ParamSet",
GOST34112012256,
2001,
)
self.process_cms(
content_info_raw,
prv_key_raw,
- "GostR3410_2012_TC26_ParamSetB",
+ "id-tc26-gost-3410-12-512-paramSetB",
GOST34112012512,
2012,
)
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": [
(
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"])
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,
)
self.process_cms(
content_info_raw,
prv_key_our,
- "GostR3410_2012_TC26_ParamSetB",
+ "id-tc26-gost-3410-12-512-paramSetB",
keker,
b"Test message",
)
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": [
(
},
),
),
- ) for spki_algorithm in (
+ ) for _ in (
id_tc26_gost3410_2012_256,
id_tc26_gost3410_2012_512,
)
_, 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
self.process_cms(
content_info_raw,
prv_key_our,
- "GostR3410_2001_CryptoPro_XchA_ParamSet",
+ "id-GostR3410-2001-CryptoPro-XchA-ParamSet",
keker,
b"Test message",
)
self.process_cms(
content_info_raw,
prv_key_our,
- "GostR3410_2012_TC26_ParamSetB",
+ "id-tc26-gost-3410-12-512-paramSetB",
keker,
b"Test message",
)