def test_new_public_keyset_handle_fails(self):
     params = ecdsa_pb2.EcdsaParams(hash_type=common_pb2.SHA256,
                                    curve=common_pb2.NIST_P256,
                                    encoding=ecdsa_pb2.DER)
     key_format = ecdsa_pb2.EcdsaKeyFormat(params=params)
     template = tink_pb2.KeyTemplate()
     template.type_url = 'type.googleapis.com/google.crypto.tink.EcdsaPublicKey'
     template.value = key_format.SerializeToString()
     with self.assertRaises(core.TinkError):
         tink.new_keyset_handle(template)
Beispiel #2
0
    def test_ecdsa_ieee(self, key_template, hash_type, curve):
        self.assertEqual(
            key_template.type_url,
            'type.googleapis.com/google.crypto.tink.EcdsaPrivateKey')
        self.assertEqual(key_template.output_prefix_type, tink_pb2.TINK)

        key_format = ecdsa_pb2.EcdsaKeyFormat()
        key_format.ParseFromString(key_template.value)
        self.assertEqual(key_format.params.hash_type, hash_type)
        self.assertEqual(key_format.params.curve, curve)
        self.assertEqual(key_format.params.encoding, ecdsa_pb2.IEEE_P1363)
def new_ecdsa_key_template(hash_type, curve_type, encoding, public=True):
  params = ecdsa_pb2.EcdsaParams(
      hash_type=hash_type, curve=curve_type, encoding=encoding)
  key_format = ecdsa_pb2.EcdsaKeyFormat(params=params)
  key_template = tink_pb2.KeyTemplate()
  if public:
    append = 'EcdsaPublicKey'
  else:
    append = 'EcdsaPrivateKey'
  key_template.type_url = 'type.googleapis.com/google.crypto.tink.' + append
  key_template.value = key_format.SerializeToString()

  return key_template
Beispiel #4
0
def create_ecdsa_key_template(
        hash_type: common_pb2.HashType, curve: common_pb2.EllipticCurveType,
        encoding: ecdsa_pb2.EcdsaSignatureEncoding) -> tink_pb2.KeyTemplate:
    """Creates a KeyTemplate containing an EcdsaKeyFormat."""
    params = ecdsa_pb2.EcdsaParams(hash_type=hash_type,
                                   curve=curve,
                                   encoding=encoding)
    key_format = ecdsa_pb2.EcdsaKeyFormat(params=params)
    key_template = tink_pb2.KeyTemplate(value=key_format.SerializeToString(),
                                        type_url=_ECDSA_KEY_TYPE_URL,
                                        output_prefix_type=tink_pb2.TINK)

    return key_template
  def test_ecdsa_ieee(self, key_template, hash_type, curve):
    self.assertEqual(key_template.type_url,
                     'type.googleapis.com/google.crypto.tink.EcdsaPrivateKey')
    self.assertEqual(key_template.output_prefix_type, tink_pb2.TINK)

    key_format = ecdsa_pb2.EcdsaKeyFormat()
    key_format.ParseFromString(key_template.value)
    self.assertEqual(key_format.params.hash_type, hash_type)
    self.assertEqual(key_format.params.curve, curve)
    self.assertEqual(key_format.params.encoding, ecdsa_pb2.IEEE_P1363)

    # Check that the template works with the key manager
    key_manager = public_key_sign_key_manager.from_cc_registry(
        key_template.type_url)
    key_manager.new_key_data(key_template)