Ejemplo n.º 1
0
 def parse_signature(hex_value):
     lmots_type = LmotsType.get_by_type_code(hex_u32_to_int(hex_value[4:8]))
     pos = 4 + LmotsSerializer.bytes(lmots_type)
     lms_type = LmsType.get_by_type_code(
         hex_u32_to_int(hex_value[pos:pos + 4]))
     pos = pos + 4 + lms_type.h * lms_type.m
     return hex_value[0:pos], hex_value[pos:]
Ejemplo n.º 2
0
 def deserialize_public_key(hex_value):
     sig_type_code = hex_u32_to_int(hex_value[0:4])
     lmots_type = LmotsType.get_by_type_code(sig_type_code)
     if len(hex_value) != 4 + 2 * lmots_type.n:
         raise ValueError("hex_value is wrong length")
     s = hex_value[4:4 + lmots_type.n]
     k = hex_value[4 + lmots_type.n:4 + 2 * lmots_type.n]
     return LmotsPublicKey(s=s, k=k, lmots_type=lmots_type)
Ejemplo n.º 3
0
 def deserialize_private_key(hex_value):
     levels = hex_u32_to_int(hex_value[0:4])
     lms_type, lmots_type, seed, i, q = LmsSerializer.deserialize_private_key(
         hex_value[4:])
     lms = Lms(lms_type=lms_type, lmots_type=lmots_type)
     lms_root_pub_key, lms_root_pvt_key = lms.generate_key_pair(seed=seed,
                                                                i=i,
                                                                q=q)
     return lms_root_pub_key, lms_root_pvt_key, levels, lms_type, lmots_type
Ejemplo n.º 4
0
 def deserialize_public_key(hex_value):
     levels = hex_u32_to_int(hex_value[0:4])
     lms_type, lmots_type, i, k = LmsSerializer.deserialize_public_key(
         hex_value[4:])
     lms_root_pub_key = LmsPublicKey(lms_type=lms_type,
                                     lmots_type=lmots_type,
                                     i=i,
                                     k=k,
                                     nodes=None)
     return lms_root_pub_key, levels
Ejemplo n.º 5
0
    def deserialize_private_key(hex_value):
        # parse out values
        lmots_type = LmsSerializer.get_lmots_type(hex_value)
        lms_type = LmsSerializer.get_lms_type(hex_value)

        seed = hex_value[8:8 + lmots_type.n]
        i = hex_value[8 + lmots_type.n:8 + lmots_type.n + lms_type.len_i]
        q = hex_u32_to_int(hex_value[8 + lmots_type.n + lms_type.len_i:8 +
                                     lmots_type.n + lms_type.len_i + 4])
        return lms_type, lmots_type, seed, i, q
Ejemplo n.º 6
0
    def deserialize_signature(hex_value):
        # extract the type code value that identifies the LMOTS algorithm used in the signature
        sig_type_code = hex_u32_to_int(hex_value[0:4])
        lmots_type = LmotsType.get_by_type_code(sig_type_code)

        if len(hex_value) != LmotsSerializer.bytes(lmots_type):
            raise ValueError("hex_value is wrong length")
        c = hex_value[4:lmots_type.n + 4]
        y = list()
        pos = lmots_type.n + 4
        for i in xrange(0, lmots_type.p):
            y.append(hex_value[pos:pos + lmots_type.n])
            pos = pos + lmots_type.n
        return LmotsSignature(c=c, y=y, lmots_type=lmots_type)
Ejemplo n.º 7
0
 def deserialize_signature(hex_value):
     hss_max_levels = 8
     levels = hex_u32_to_int(hex_value[0:4]) + 1
     if levels > hss_max_levels:
         raise ValueError("levels exceeds max level value")
     sig_list = list()
     pub_list = list()
     tmp = hex_value[4:]
     for i in xrange(0, levels - 1):
         lms_sig, tmp = LmsSerializer.parse_signature(tmp)
         sig_list.append(lms_sig)
         lms_pub, tmp = LmsSerializer.parse_public_key(tmp)
         pub_list.append(lms_pub)
     msg_sig = tmp
     return levels, pub_list, sig_list, msg_sig
Ejemplo n.º 8
0
    def deserialize_signature(hex_value):
        q = hex_u32_to_int(hex_value[0:4])
        lmots_type = LmsSerializer.get_lmots_type(hex_value)
        pos = 4 + LmotsSerializer.bytes(lmots_type)
        lmots_sig = hex_value[4:pos]
        lms_type = LmsSerializer.get_lms_type(hex_value[pos:pos + 4])

        if q >= 2**lms_type.h:
            raise ValueError("value of q is not valid")
        pos = pos + 4
        path = list()
        for i in xrange(0, lms_type.h):
            path.append(hex_value[pos:pos + lms_type.m])
            pos = pos + lms_type.m
        return lms_type, q, lmots_sig, path
Ejemplo n.º 9
0
    def deserialize_print_hex(hex_value):

        lms_type = LmsSerializer.get_lms_type(hex_value)
        lmots_type = LmsSerializer.get_lmots_type(hex_value)

        StringFormat.line()
        print "LMS private key"

        seed = hex_value[8:8 + lmots_type.n]
        i = hex_value[8 + lmots_type.n:8 + lmots_type.n + lms_type.len_i]
        q = hex_u32_to_int(hex_value[8 + lmots_type.n + lms_type.len_i:8 +
                                     lmots_type.n + lms_type.len_i + 4])
        StringFormat.format_hex("lms_type", u32str(lms_type))
        StringFormat.format_hex("lmots_type", u32str(lmots_type))
        StringFormat.format_hex("seed", seed)
        StringFormat.format_hex("I", i)
        StringFormat.format_hex("leaf_num", u32str(q))
        StringFormat.line()
Ejemplo n.º 10
0
 def get_lms_type(hex_value):
     # extract the type code value that identifies the LMS algorithm
     sig_type_code_lms = hex_u32_to_int(hex_value[0:4])
     lms_type = LmsType.get_by_type_code(sig_type_code_lms)
     return lms_type
Ejemplo n.º 11
0
 def get_lmots_type(hex_value):
     # extract the type code value that identifies the LMOTS algorithm
     sig_type_code_lmots = hex_u32_to_int(hex_value[4:8])
     lmots_type = LmotsType.get_by_type_code(sig_type_code_lmots)
     return lmots_type