示例#1
0
    def test_invalid_key(self, backend):
        kdf = KBKDFHMAC(
            hashes.SHA256(),
            Mode.CounterMode,
            32,
            4,
            4,
            CounterLocation.BeforeFixed,
            b"label",
            b"context",
            None,
            backend=backend,
        )

        key = kdf.derive(b"material")

        kdf = KBKDFHMAC(
            hashes.SHA256(),
            Mode.CounterMode,
            32,
            4,
            4,
            CounterLocation.BeforeFixed,
            b"label",
            b"context",
            None,
            backend=backend,
        )

        with pytest.raises(InvalidKey):
            kdf.verify(b"material2", key)
示例#2
0
    def test_invalid_key(self):
        kdf = KBKDFHMAC(hashes.SHA256(),
                        Mode.CounterMode,
                        32,
                        4,
                        4,
                        CounterLocation.BeforeFixed,
                        b'label',
                        b'context',
                        None,
                        backend=default_backend())

        key = kdf.derive(b"material")

        kdf = KBKDFHMAC(hashes.SHA256(),
                        Mode.CounterMode,
                        32,
                        4,
                        4,
                        CounterLocation.BeforeFixed,
                        b'label',
                        b'context',
                        None,
                        backend=default_backend())

        with pytest.raises(InvalidKey):
            kdf.verify(b"material2", key)
示例#3
0
    def test_invalid_key(self, backend):
        kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 32, 4, 4,
                        CounterLocation.BeforeFixed, b'label', b'context',
                        None, backend=backend)

        key = kdf.derive(b"material")

        kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 32, 4, 4,
                        CounterLocation.BeforeFixed, b'label', b'context',
                        None, backend=backend)

        with pytest.raises(InvalidKey):
            kdf.verify(b"material2", key)
示例#4
0
    def test_already_finalized(self, backend):
        kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 32, 4, 4,
                        CounterLocation.BeforeFixed, b'label', b'context',
                        None, backend=backend)

        kdf.derive(b'material')

        with pytest.raises(AlreadyFinalized):
            kdf.derive(b'material2')

        kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 32, 4, 4,
                        CounterLocation.BeforeFixed, b'label', b'context',
                        None, backend=backend)

        key = kdf.derive(b'material')

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b'material', key)

        kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 32, 4, 4,
                        CounterLocation.BeforeFixed, b'label', b'context',
                        None, backend=backend)
        kdf.verify(b'material', key)

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b"material", key)
示例#5
0
    def test_already_finalized(self, backend):
        kdf = KBKDFHMAC(
            hashes.SHA256(),
            Mode.CounterMode,
            32,
            4,
            4,
            CounterLocation.BeforeFixed,
            b"label",
            b"context",
            None,
            backend=backend,
        )

        kdf.derive(b"material")

        with pytest.raises(AlreadyFinalized):
            kdf.derive(b"material2")

        kdf = KBKDFHMAC(
            hashes.SHA256(),
            Mode.CounterMode,
            32,
            4,
            4,
            CounterLocation.BeforeFixed,
            b"label",
            b"context",
            None,
            backend=backend,
        )

        key = kdf.derive(b"material")

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b"material", key)

        kdf = KBKDFHMAC(
            hashes.SHA256(),
            Mode.CounterMode,
            32,
            4,
            4,
            CounterLocation.BeforeFixed,
            b"label",
            b"context",
            None,
            backend=backend,
        )
        kdf.verify(b"material", key)

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b"material", key)
示例#6
0
    def test_already_finalized(self):
        kdf = KBKDFHMAC(hashes.SHA256(),
                        Mode.CounterMode,
                        32,
                        4,
                        4,
                        CounterLocation.BeforeFixed,
                        b'label',
                        b'context',
                        None,
                        backend=default_backend())

        kdf.derive(b'material')

        with pytest.raises(AlreadyFinalized):
            kdf.derive(b'material2')

        kdf = KBKDFHMAC(hashes.SHA256(),
                        Mode.CounterMode,
                        32,
                        4,
                        4,
                        CounterLocation.BeforeFixed,
                        b'label',
                        b'context',
                        None,
                        backend=default_backend())

        key = kdf.derive(b'material')

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b'material', key)

        kdf = KBKDFHMAC(hashes.SHA256(),
                        Mode.CounterMode,
                        32,
                        4,
                        4,
                        CounterLocation.BeforeFixed,
                        b'label',
                        b'context',
                        None,
                        backend=default_backend())
        kdf.verify(b'material', key)

        with pytest.raises(AlreadyFinalized):
            kdf.verify(b"material", key)