Beispiel #1
0
    def test_3(self):
        curve_obj = asymmetric.ECC_NISTP384()
        priv = util.be2int(self.TEST_VECTORS['key3w']['private'])
        pub = tuple(map(util.be2int, self.TEST_VECTORS['key3w']['public']))
        hash_func = lambda m: util.be2int(hashlib.sha384(m).digest())
        hash_bits = 384
        msg = self.TEST_VECTORS['msg3']['msg']
        k = util.be2int(self.TEST_VECTORS['msg3']['k'])
        reference_sig = tuple(
            map(util.be2int, self.TEST_VECTORS['msg3']['sig']))

        self._test_ecdsa(curve_obj, priv, pub, hash_func, hash_bits, msg, k,
                         reference_sig)
Beispiel #2
0
    def test_big_endian_conv(self):
        self.assertEquals(0, util.be2int('\x00'))
        self.assertEquals(1, util.be2int('\x01'))
        self.assertEquals(0xffaa, util.be2int('\xff\xaa'))
        self.assertEquals(0xccbbaa, util.be2int('\xcc\xbb\xaa'))

        self.assertEquals('\x00', util.int2be(0, 1))
        self.assertEquals('\x00\x00', util.int2be(0, 2))
        self.assertEquals('\x01', util.int2be(1, 1))
        self.assertEquals('\x00\x01', util.int2be(1, 2))
        self.assertEquals('\x00\x00\xaa\xff', util.int2be(0xaaff, 4))

        self.assertEquals('\xdd\xcc\xbb\xaa', util.int2be(0xddccbbaa, 4))

        self.assertRaises(ValueError, util.int2be, 0xaabbccdd, 2)
Beispiel #3
0
    def test_break(self):
        curve_obj = asymmetric.ECC_NISTP256()
        priv = util.be2int(self.TEST_VECTORS['key1w']['private'])
        pub = tuple(map(util.be2int, self.TEST_VECTORS['key1w']['public']))
        hash_func = lambda m: util.be2int(hashlib.sha256(m).digest())
        hash_bits = 256

        msg1 = self.TEST_VECTORS['msg1']['msg']
        msg2 = self.TEST_VECTORS['msg2']['msg']
        k = util.be2int(self.TEST_VECTORS['msg1']['k'])

        sig1 = ecdsa.ecdsa_sign(curve_obj, hash_func, hash_bits, priv, msg1, k)

        sig2 = ecdsa.ecdsa_sign(curve_obj, hash_func, hash_bits, priv, msg2, k)

        recovered = ecdsa.break_ecdsa(curve_obj, hash_func, hash_bits, sig1,
                                      sig2, msg1, msg2)

        self.assertEquals((k, priv), recovered)