예제 #1
0
def new_ecdsa_key_template(hash_type, curve_type, encoding):
    key_format = ecdsa_pb2.EcdsaKeyFormat()
    key_format.params.hash_type = hash_type
    key_format.params.curve = curve_type
    key_format.params.encoding = encoding
    key_template = tink_pb2.KeyTemplate()
    key_template.type_url = (
        'type.googleapis.com/google.crypto.tink.EcdsaPrivateKey')
    key_template.value = key_format.SerializeToString()
    return key_template
예제 #2
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
예제 #3
0
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
예제 #4
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)

        # 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)