Exemple #1
0
def test_symmetric_key_derivation(kid, alg, key_ops, base_iv, k, salt, algo,
                                  ctx_alg, u, v, pub, priv, context, cek):
    key = SymmetricKey(kid=kid, alg=alg, key_ops=key_ops, base_iv=base_iv, k=k)

    ctx = CoseKDFContext(ctx_alg, u, v, pub, priv)
    assert ctx.encode() == context

    assert key.hmac_key_derivation(ctx, algo, salt) == cek
Exemple #2
0
    def _(cls,
          private_key: SymmetricKey,
          public_key=None,
          alg: Optional['CoseAlgorithms'] = None,
          context: 'CoseKDFContext' = None,
          curve=None,
          salt: bytes = b'',
          expose_secret: bool = False):

        _ = public_key
        _ = curve

        kek = private_key.hmac_key_derivation(context, alg, salt)

        if expose_secret:
            return private_key.private_bytes, kek
        else:
            return kek