Ejemplo n.º 1
0
 def test_32(self):
     self.assertEqual(
         GOST341194(
             b'This is message, length=32 bytes',
             "GostR3411_94_CryptoProParamSet",
         ).hexdigest(),
         "eb48de3e89e71bcb695fc752d617fae757f34fa77fa58ee114c5bdb7f7c2ef2c",
     )
Ejemplo n.º 2
0
 def test_message_digest(self):
     self.assertEqual(
         GOST341194(
             b'message digest',
             "GostR3411_94_CryptoProParamSet",
         ).hexdigest(),
         "a01b72299bc39a540fd672a99a72b4bdfe74417386986efaeb01a42add4160bc",
     )
Ejemplo n.º 3
0
 def test_dog(self):
     self.assertEqual(
         GOST341194(
             b'The quick brown fox jumps over the lazy dog',
             "GostR3411_94_CryptoProParamSet",
         ).hexdigest(),
         "760a8365d570476e787254761be7656774021b1f3de56f588c501a364a290490",
     )
Ejemplo n.º 4
0
 def test_rfc50(self):
     self.assertEqual(
         GOST341194(
             b'Suppose the original message has length = 50 bytes',
             "GostR3411_94_TestParamSet",
         ).hexdigest(),
         "0852f5623b89dd57aeb4781fe54df14eeafbc1350613763a0d770aa657ba1a47",
     )
Ejemplo n.º 5
0
 def test_dog(self):
     self.assertEqual(
         GOST341194(
             b'The quick brown fox jumps over the lazy dog',
             "GostR3411_94_TestParamSet",
         ).hexdigest(),
         "94421f6d370fa1d16ba7ac5e31296529c968047dca9bf4258ac59a0c41fab777",
     )
Ejemplo n.º 6
0
 def test_cog(self):
     self.assertEqual(
         GOST341194(
             b'The quick brown fox jumps over the lazy cog',
             "GostR3411_94_TestParamSet",
         ).hexdigest(),
         "45c4ee4ee1d25091312135540d6702e6677f7a73b5da31e10b8bb7aadac4eba3",
     )
Ejemplo n.º 7
0
 def test_50(self):
     self.assertEqual(
         GOST341194(
             b'Suppose the original message has length = 50 bytes',
             "GostR3411_94_CryptoProParamSet",
         ).hexdigest(),
         "1150a63031dc611a5f5e40d93153f74ebde8216f6792c25a91cfcabc5c0c73c3",
     )
Ejemplo n.º 8
0
 def test_rfc32(self):
     self.assertEqual(
         GOST341194(
             b'This is message, length=32 bytes',
             "GostR3411_94_TestParamSet",
         ).hexdigest(),
         "faff37a615a816691cff3ef8b68ca247e09525f39f8119832eb81975d366c4b1",
     )
Ejemplo n.º 9
0
def sign(private_key, data):
    """ Sign data

    :param private_key: private key to sign with
    :type private_key: bytes, 32 bytes
    :param bytes data: arbitrary data
    :return: signature
    :rtype: bytes, 64 bytes
    """
    curve = GOST3410Curve(*CURVE_PARAMS[DEFAULT_CURVE])
    return _sign(
        curve,
        bytes2long(private_key[::-1]),
        GOST341194(data, GOST341194_SBOX).digest(),
    )
Ejemplo n.º 10
0
def verify(public_key, data, signature):
    """ Verify signature

    :param public_key: public key to verify with
    :type public_key: bytes, 64 bytes
    :param bytes data: arbitrary data
    :type signature: bytes, 64 bytes
    :rtype: bool
    """
    curve = GOST3410Curve(*CURVE_PARAMS[DEFAULT_CURVE])
    public_key = public_key[::-1]
    return _verify(
        curve,
        bytes2long(public_key[32:]),
        bytes2long(public_key[:32]),
        GOST341194(data, GOST341194_SBOX).digest(),
        signature,
    )
Ejemplo n.º 11
0
def kek(curve, private_key, ukm, pubkey):
    """ Make Diffie-Hellman computation

    :param GOST3410Curve curve: curve to use
    :param long private_key: private key
    :param ukm: UKM value (VKO-factor)
    :type ukm: bytes, 8 bytes
    :param pubkey: public key's part
    :type pubkey: (long, long)
    :return: Key Encryption Key (shared key)
    :rtype: bytes, 32 bytes

    Shared Key Encryption Key computation is based on
    :rfc:`4357` VKO GOST 34.10-2001 with little-endian
    hash output.
    """
    key = curve.exp(private_key, pubkey[0], pubkey[1])
    key = curve.exp(bytes2long(24 * b'\x00' + ukm), key[0], key[1])
    return GOST341194((long2bytes(key[1]) + long2bytes(key[0]))[::-1],
                      "GostR3411_94_CryptoProParamSet").digest()[::-1]
Ejemplo n.º 12
0
 def test_Us(self):
     self.assertEqual(
         GOST341194(128 * b'U',
                    "GostR3411_94_CryptoProParamSet").hexdigest(),
         "e8c449f608104c512710cd37fded920df1e86b211623fa27f4bb914661c74a1c",
     )
Ejemplo n.º 13
0
 def test_a(self):
     self.assertEqual(
         GOST341194(b'a', "GostR3411_94_CryptoProParamSet").hexdigest(),
         "1130402fcfaaf1ef3c13e3173f105a715580f7c97900af37bf832128dd524ce7",
     )
Ejemplo n.º 14
0
 def test_Us(self):
     self.assertEqual(
         GOST341194(128 * b'U', "GostR3411_94_TestParamSet").hexdigest(),
         "a43357fee8a926d9522a06870a66251c553e2774a0851d0cef0c1825eda3a353",
     )
Ejemplo n.º 15
0
 def test_message_digest(self):
     self.assertEqual(
         GOST341194(b'message digest',
                    "GostR3411_94_TestParamSet").hexdigest(),
         "4d9a88a416de2fdb72de483f27652b5869243dec59be0cb6992c8fb1ec3444ad",
     )
Ejemplo n.º 16
0
 def test_abc(self):
     self.assertEqual(
         GOST341194(b'abc', "GostR3411_94_TestParamSet").hexdigest(),
         "1dd5a4067c49703b75bc75c9290f5ecbb5eb85229e7277a2b2b14fc4484313f3",
     )
Ejemplo n.º 17
0
 def test_a(self):
     self.assertEqual(
         GOST341194(b'a', "GostR3411_94_TestParamSet").hexdigest(),
         "dd14f362cefd49f873a5c644431b87219c3449661f808ac8e9667c369e532cd4",
     )
Ejemplo n.º 18
0
 def test_abc(self):
     self.assertEqual(
         GOST341194(b'abc', "GostR3411_94_CryptoProParamSet").hexdigest(),
         "2cd42ff986293b167e994381ed59747414dd24953677762d39d718bf6d0585b2",
     )
Ejemplo n.º 19
0
 def test_empty(self):
     self.assertEqual(
         GOST341194(b'', "GostR3411_94_CryptoProParamSet").hexdigest(),
         "c056d64c2383c44a58139c9b560111ac133e43fb840f838714840ca33c5f1e98",
     )
Ejemplo n.º 20
0
 def test_empty(self):
     self.assertEqual(
         GOST341194(b'', "GostR3411_94_TestParamSet").hexdigest(),
         "8d0f49492c91f45a68ff5c05d2c2b4ab78027b9aab5ce3feff5267c49cb985ce",
     )