Exemple #1
0
def _create_jwt_rsa_ssa_pss_template(
        algorithm: jwt_rsa_ssa_pss_pb2.JwtRsaSsaPssAlgorithm,
        modulus_size: int,
        output_prefix_type: tink_pb2.OutputPrefixType) -> tink_pb2.KeyTemplate:
    key_format = jwt_rsa_ssa_pss_pb2.JwtRsaSsaPssKeyFormat(
        algorithm=algorithm,
        modulus_size_in_bits=modulus_size,
        public_exponent=big_integer_util.num_to_bytes(_F4))
    return tink_pb2.KeyTemplate(
        type_url=
        'type.googleapis.com/google.crypto.tink.JwtRsaSsaPssPrivateKey',
        value=key_format.SerializeToString(),
        output_prefix_type=output_prefix_type)
Exemple #2
0
def _create_rsa_ssa_pkcs1_key_template(
        hash_type: common_pb2.HashType, modulus_size: int,
        public_exponent: int) -> tink_pb2.KeyTemplate:
    """Creates a KeyTemplate containing an RsaSsaPkcs1KeyFormat."""
    params = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1Params(hash_type=hash_type)
    key_format = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1KeyFormat(
        params=params,
        modulus_size_in_bits=modulus_size,
        public_exponent=big_integer_util.num_to_bytes(public_exponent))
    key_template = tink_pb2.KeyTemplate(value=key_format.SerializeToString(),
                                        type_url=_RSA_PKCS1_KEY_TYPE_URL,
                                        output_prefix_type=tink_pb2.TINK)

    return key_template
Exemple #3
0
def _create_rsa_ssa_pss_key_template(
        sig_hash: common_pb2.HashType, mgf1_hash: common_pb2.HashType,
        salt_length: int, modulus_size: int,
        public_exponent: int) -> tink_pb2.KeyTemplate:
    """Creates a KeyTemplate containing an RsaSsaPssKeyFormat."""
    params = rsa_ssa_pss_pb2.RsaSsaPssParams(sig_hash=sig_hash,
                                             mgf1_hash=mgf1_hash,
                                             salt_length=salt_length)
    key_format = rsa_ssa_pss_pb2.RsaSsaPssKeyFormat(
        params=params,
        modulus_size_in_bits=modulus_size,
        public_exponent=big_integer_util.num_to_bytes(public_exponent))
    key_template = tink_pb2.KeyTemplate(value=key_format.SerializeToString(),
                                        type_url=_RSA_PSS_KEY_TYPE_URL,
                                        output_prefix_type=tink_pb2.TINK)

    return key_template
Exemple #4
0
 def test_num_to_bytes_minus_one_overflow(self):
     with self.assertRaises(OverflowError):
         big_integer_util.num_to_bytes(-1)
Exemple #5
0
 def test_num_to_bytes(self, number, expected):
     self.assertEqual(big_integer_util.num_to_bytes(number), expected)
Exemple #6
0
 def test_bytes_to_num(self):
     for i in range(100000):
         big_int_bytes = big_integer_util.num_to_bytes(i)
         self.assertEqual(int.from_bytes(big_int_bytes, byteorder='big'), i)