Exemplo n.º 1
0
    def test_profileB(self):
        hn_pubkey = unhexlify(
            '0272DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD1'
        )  # compressed
        hn_privkey = unhexlify(
            'F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA')
        eph_pubkey = unhexlify(
            '039AAB8376597021E855679A9778EA0B67396E68C66DF32C0F41E9ACCA2DA9B9D1'
        )  # compressed
        eph_privkey = unhexlify(
            '99798858A1DC6A2C68637149A4B1DBFD1FDFF5ADDD62A2142F06699ED7602529')
        shared_key = unhexlify(
            '6C7E6518980025B982FBB2FF746E3C2E85A196D252099A7AD23EA7B4C0959CAE')
        #
        plaintext = bytes.fromhex('00012080F6')
        ciphertext = unhexlify('46A33FC271')
        mactag = unhexlify('6AC7DAE96AA30A4D')

        x1 = ECDH_SECP256R1(raw_keypair=(eph_privkey, eph_pubkey))
        x2 = ECDH_SECP256R1(raw_keypair=(hn_privkey, hn_pubkey))
        ue = ECIES_UE(profile='B')
        ue.EC._load_raw_keypair(eph_privkey, eph_pubkey)  # pylint: disable=W0212
        hn = ECIES_HN(None, profile='B', raw_keypair=(hn_privkey, hn_pubkey))
        ue.generate_sharedkey(hn_pubkey, fresh=False)
        ue_pk, ue_ct, ue_mac = ue.protect(plaintext)
        hn_ct = hn.unprotect(ue_pk, ue_ct, ue_mac)

        self.assertEqual(x1.generate_sharedkey(hn_pubkey), shared_key)
        self.assertEqual(x2.generate_sharedkey(eph_pubkey), shared_key)
        self.assertEqual(ue_ct, ciphertext)
        self.assertEqual(ue_mac, mactag)
        self.assertEqual(hn_ct, plaintext)
Exemplo n.º 2
0
 def __init__(self, hn_priv_key, profile='A', raw_keypair=None):
     if profile == 'A':
         self.EC = X25519(loc_privkey=hn_priv_key)
     elif profile == 'B':
         if isinstance(raw_keypair, (tuple, list)) and len(raw_keypair) == 2:
             self.EC = ECDH_SECP256R1(raw_keypair=raw_keypair)
         else:
             self.EC = ECDH_SECP256R1(loc_privkey=hn_priv_key)
     else:
         raise CMException('unknown ECIES profile %s' % profile)
Exemplo n.º 3
0
 def __init__(self, profile):
     if profile == 'A':
         self.EC = X25519()
     elif profile == 'B':
         self.EC = ECDH_SECP256R1()
     else:
         raise CMException('unknown ECIES profile %s' % profile)
     self.ephemeral_key = None
     self.shared_key = None
Exemplo n.º 4
0
    def core_home_network_key_gen(self):
        """
        core_home_network_key_gen
        """

        if self.profile == "ProfileA":
            ec = X25519()
        elif self.profile == "ProfileB":
            ec = ECDH_SECP256R1()

        if ec:
            ec.generate_keypair()
        else:
            return None

        self.home_network_key_pair = home_network_key_pair(
            ec.get_pubkey(),
            ec.get_privkey(),
        )