Various fixes in GT signing

Note that the TLV encoding fix affects the signature file format. That is quite unavoidable, though, as the current implementation is not really consistent, using 0x20 for the TLV16 flag in some places and 0x80 elsewhere.