(M, emLen, h)
return EM
Implements EMSA-PKCS1-V1_5-ENCODE() function described in Sect.
    9.2 of RFC 3447.

    Input:
       M    : message to be encode, an octet string
       emLen: intended length in octets of the encoded message, at least
              tLen + 11, where tLen is the octet length of the DER encoding
              T of a certain value computed during the encoding operation.
       h    : hash function name (in 'md2', 'md4', 'md5', 'sha1', 'tls',
              'sha256', 'sha384'). hLen denotes the length in octets of
              the hash function output.

    Output:
       encoded message, an octet string of length emLen

    On error, None is returned.
Implements EMSA-PKCS1-V1_5-ENCODE() function described in Sect.
    9.2 of RFC 3447.
Implements EMSA - PKCS1 - V1_5 - ENCODE () function described in Sect . 9 . 2 of RFC 3447 .
def pkcs_emsa_pkcs1_v1_5_encode(M, emLen, h): # section 9.2 of RFC 3447
    """
    Implements EMSA-PKCS1-V1_5-ENCODE() function described in Sect.
    9.2 of RFC 3447.

    Input:
       M    : message to be encode, an octet string
       emLen: intended length in octets of the encoded message, at least
              tLen + 11, where tLen is the octet length of the DER encoding
              T of a certain value computed during the encoding operation.
       h    : hash function name (in 'md2', 'md4', 'md5', 'sha1', 'tls',
              'sha256', 'sha384'). hLen denotes the length in octets of
              the hash function output.

    Output:
       encoded message, an octet string of length emLen

    On error, None is returned.
    """
    hLen = _hashFuncParams[h][0]                             # 1)
    hFunc = _hashFuncParams[h][1]
    H = hFunc(M)
    hLeadingDigestInfo = _hashFuncParams[h][2]               # 2)
    T = hLeadingDigestInfo + H
    tLen = len(T)
    if emLen < tLen + 11:                                    # 3)
        warning("pkcs_emsa_pkcs1_v1_5_encode: intended encoded message length too short")
        return None
    PS = '\xff'*(emLen - tLen - 3)                           # 4)
    EM = '\x00' + '\x01' + PS + '\x00' + T                   # 5)
    return EM
def pkcs_emsa_pkcs1_v1_5_encode ( M , emLen , h ) : # section 9.2 of RFC 3447 hLen = _hashFuncParams [ h ] [ 0 ] # 1) hFunc = _hashFuncParams [ h ] [ 1 ] H = hFunc ( M ) hLeadingDigestInfo = _hashFuncParams [ h ] [ 2 ] # 2) T = hLeadingDigestInfo + H tLen = len ( T ) if emLen < tLen + 11 : # 3) warning ( "pkcs_emsa_pkcs1_v1_5_encode: intended encoded message length too short" ) return None PS = '\xff' * ( emLen - tLen - 3 ) # 4) EM = '\x00' + '\x01' + PS + '\x00' + T # 5) return EM