FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* give option to check length value found against index. 1 to check 0 to not */
give option to check length value found against index. 1 to check 0 to not
give option to check length value found against index . 1 to check 0 to not
int GetLength_ex(const byte* input, word32* inOutIdx, int* len,
                           word32 maxIdx, int check)
{
    int     length = 0;
    word32  idx = *inOutIdx;
    byte    b;
    *len = 0;    
    if ((idx + 1) > maxIdx) {   
        WOLFSSL_MSG("GetLength bad index on input");
        return BUFFER_E;
    }
    b = input[idx++];
    if (b >= ASN_LONG_LENGTH) {
        word32 bytes = b & 0x7F;
        if ((idx + bytes) > maxIdx) {   
            WOLFSSL_MSG("GetLength bad long length");
            return BUFFER_E;
        }
        if (bytes > sizeof(length)) {
            return ASN_PARSE_E;
        }
        while (bytes--) {
            b = input[idx++];
            length = (length << 8) | b;
        }
        if (length < 0) {
            return ASN_PARSE_E;
        }
    }
    else
        length = b;
    if (check && (idx + length) > maxIdx) {   
        WOLFSSL_MSG("GetLength value exceeds buffer length");
        return BUFFER_E;
    }
    *inOutIdx = idx;
    if (length > 0)
        *len = length;
    return length;
}
int GetLength_ex ( const byte * input , word32 * inOutIdx , int * len , word32 maxIdx , int check ) { int length = 0 ; word32 idx = * inOutIdx ; byte b ; * len = 0 ; if ( ( idx + 1 ) > maxIdx ) { WOLFSSL_MSG ( " " ) ; return BUFFER_E ; } b = input [ idx ++ ] ; if ( b >= ASN_LONG_LENGTH ) { word32 bytes = b & 0x7F ; if ( ( idx + bytes ) > maxIdx ) { WOLFSSL_MSG ( " " ) ; return BUFFER_E ; } if ( bytes > sizeof ( length ) ) { return ASN_PARSE_E ; } while ( bytes -- ) { b = input [ idx ++ ] ; length = ( length << 8 ) | b ; } if ( length < 0 ) { return ASN_PARSE_E ; } } else length = b ; if ( check && ( idx + length ) > maxIdx ) { WOLFSSL_MSG ( " " ) ; return BUFFER_E ; } * inOutIdx = idx ; if ( length > 0 ) * len = length ; return length ; }
give option to check length value found against index.
give option to check length value found against index .
/* default length */ /* for first read */ /* for reading bytes */ /* for user of length */