src/script/interpreter.cpp
bool static IsDERSignature(const valtype &vchSig) {

    if (vchSig.size() < 9) {
        //  Non-canonical signature: too short
        return false;
    }
    if (vchSig.size() > 73) {
        // Non-canonical signature: too long
        return false;
    }
    if (vchSig[0] != 0x30) {
        //  Non-canonical signature: wrong type
        return false;
    }
    if (vchSig[1] != vchSig.size()-3) {
        //  Non-canonical signature: wrong length marker
        return false;
    }
    unsigned int nLenR = vchSig[3];
    if (5 + nLenR >= vchSig.size()) {
        //  Non-canonical signature: S length misplaced
        return false;
    }
    unsigned int nLenS = vchSig[5+nLenR];
    if ((unsigned long)(nLenR+nLenS+7) != vchSig.size()) {
        //  Non-canonical signature: R+S length mismatch
        return false;
    }

    const unsigned char *R = &vchSig[4];
    if (R[-2] != 0x02) {
        //  Non-canonical signature: R value type mismatch
        return false;
    }
    if (nLenR == 0) {
        //  Non-canonical signature: R length is zero
        return false;
    }
    if (R[0] & 0x80) {
        //  Non-canonical signature: R value negative
        return false;
    }
    if (nLenR > 1 && (R[0] == 0x00) && !(R[1] & 0x80)) {
        //  Non-canonical signature: R value excessively padded
        return false;
    }

    const unsigned char *S = &vchSig[6+nLenR];
    if (S[-2] != 0x02) {
        //  Non-canonical signature: S value type mismatch
        return false;
    }
    if (nLenS == 0) {
        //  Non-canonical signature: S length is zero
        return false;
    }
    if (S[0] & 0x80) {
        //  Non-canonical signature: S value negative
        return false;
    }
    if (nLenS > 1 && (S[0] == 0x00) && !(S[1] & 0x80)) {
        //  Non-canonical signature: S value excessively padded
        return false;
    }
    return true;
}
/**
 * A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
 * Where R and S are not negative (their first byte has its highest bit not set), and not
 * excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
 * in which case a single 0 byte is necessary and even required).
 * 
 * See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
 */
A canonical signature exists of: <30>  <02>   <02>   
Where R and S are not negative (their first byte has its highest bit not set), and not
excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
in which case a single 0 byte is necessary and even required).


A canonical signature exists of : <30 > <02 > <02 > Where R and S are not negative ( their first byte has its highest bit not set ) and not excessively padded ( do not start with a 0 byte unless an otherwise negative number follows in which case a single 0 byte is necessary and even required ) .
bool static IsDERSignature(const valtype &vchSig) {
    if (vchSig.size() < 9) {
        return false;
    }
    if (vchSig.size() > 73) {
        return false;
    }
    if (vchSig[0] != 0x30) {
        return false;
    }
    if (vchSig[1] != vchSig.size()-3) {
        return false;
    }
    unsigned int nLenR = vchSig[3];
    if (5 + nLenR >= vchSig.size()) {
        return false;
    }
    unsigned int nLenS = vchSig[5+nLenR];
    if ((unsigned long)(nLenR+nLenS+7) != vchSig.size()) {
        return false;
    }
    const unsigned char *R = &vchSig[4];
    if (R[-2] != 0x02) {
        return false;
    }
    if (nLenR == 0) {
        return false;
    }
    if (R[0] & 0x80) {
        return false;
    }
    if (nLenR > 1 && (R[0] == 0x00) && !(R[1] & 0x80)) {
        return false;
    }
    const unsigned char *S = &vchSig[6+nLenR];
    if (S[-2] != 0x02) {
        return false;
    }
    if (nLenS == 0) {
        return false;
    }
    if (S[0] & 0x80) {
        return false;
    }
    if (nLenS > 1 && (S[0] == 0x00) && !(S[1] & 0x80)) {
        return false;
    }
    return true;
}
bool static IsDERSignature ( const valtype & vchSig ) { if ( vchSig . size ( ) < 9 ) { return false ; } if ( vchSig . size ( ) > 73 ) { return false ; } if ( vchSig [ 0 ] != 0x30 ) { return false ; } if ( vchSig [ 1 ] != vchSig . size ( ) - 3 ) { return false ; } unsigned int nLenR = vchSig [ 3 ] ; if ( 5 + nLenR >= vchSig . size ( ) ) { return false ; } unsigned int nLenS = vchSig [ 5 + nLenR ] ; if ( ( unsigned long ) ( nLenR + nLenS + 7 ) != vchSig . size ( ) ) { return false ; } const unsigned char * R = & vchSig [ 4 ] ; if ( R [ -2 ] != 0x02 ) { return false ; } if ( nLenR == 0 ) { return false ; } if ( R [ 0 ] & 0x80 ) { return false ; } if ( nLenR > 1 && ( R [ 0 ] == 0x00 ) && ! ( R [ 1 ] & 0x80 ) ) { return false ; } const unsigned char * S = & vchSig [ 6 + nLenR ] ; if ( S [ -2 ] != 0x02 ) { return false ; } if ( nLenS == 0 ) { return false ; } if ( S [ 0 ] & 0x80 ) { return false ; } if ( nLenS > 1 && ( S [ 0 ] == 0x00 ) && ! ( S [ 1 ] & 0x80 ) ) { return false ; } return true ; }
A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
 Where R and S are not negative (their first byte has its highest bit not set), and not
 excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
 in which case a single 0 byte is necessary and even required).
A canonical signature exists of : <30 > <total len > <02 > <len R > <R > <02 > <len S > <S > <hashtype > Where R and S are not negative ( their first byte has its highest bit not set ) and not excessively padded ( do not start with a 0 byte unless an otherwise negative number follows in which case a single 0 byte is necessary and even required ) .
//  Non-canonical signature: too short // Non-canonical signature: too long //  Non-canonical signature: wrong type //  Non-canonical signature: wrong length marker //  Non-canonical signature: S length misplaced //  Non-canonical signature: R+S length mismatch //  Non-canonical signature: R value type mismatch //  Non-canonical signature: R length is zero //  Non-canonical signature: R value negative //  Non-canonical signature: R value excessively padded //  Non-canonical signature: S value type mismatch //  Non-canonical signature: S length is zero //  Non-canonical signature: S value negative //  Non-canonical signature: S value excessively padded