Esempio n. 1
0
    def _generate_ephemeral_key(self) -> None:
        """
        Generate a new ephemeral key if the key was not already set.

        :return: None
        """

        if self.ephemeral_key is not None:
            return

        chosen_suite = CipherSuite(self.cipher_suite)

        if chosen_suite.dh_curve in [
                CoseEllipticCurves.X25519, CoseEllipticCurves.X448
        ]:
            self.ephemeral_key = OKP.generate_key(
                CoseAlgorithms.DIRECT,
                curve_type=chosen_suite.dh_curve,
                key_ops=KeyOps.SIGN)
        else:
            self.ephemeral_key = EC2.generate_key(
                CoseAlgorithms.DIRECT,
                curve_type=chosen_suite.dh_curve,
                key_ops=KeyOps.SIGN)
Esempio n. 2
0
def test_okp_key_generation():
    key = OKP.generate_key(CoseAlgorithms.EDDSA, KeyOps.SIGN,
                           CoseEllipticCurves.X25519)
    assert isinstance(key, OKP)