FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Set small integer, 32 bits or less. DER encoding with no leading 0s
 * returns total amount written including ASN tag and length byte on success */
Set small integer, 32 bits or less. DER encoding with no leading 0s
returns total amount written including ASN tag and length byte on success
Set small integer 32 bits or less . DER encoding with no leading 0s returns total amount written including ASN tag and length byte on success
int SetShortInt(byte* input, word32* inOutIdx, word32 number, word32 maxIdx)
{
    word32 idx = *inOutIdx;
    word32 len = 0;
    int    i;
    byte ar[MAX_LENGTH_SZ];
    if ((idx + 2) > maxIdx)
        return BUFFER_E;
    input[idx++] = ASN_INTEGER;
    idx++; 
    if (MAX_LENGTH_SZ + idx > maxIdx)
        return ASN_PARSE_E;
    XMEMSET(ar, 0, MAX_LENGTH_SZ);
    c32toa(number, ar);
    for (i = 0; i < MAX_LENGTH_SZ; i++) {
        if (ar[i] != 0) {
            break;
        }
    }
    if (i == MAX_LENGTH_SZ) {
        input[idx++] = 0; len++;
    }
    for (; i < MAX_LENGTH_SZ && idx < maxIdx; i++) {
        input[idx++] = ar[i]; len++;
    }
    input[*inOutIdx + 1] = (byte)len;
    *inOutIdx = idx;
    return len + 2; 
}
int SetShortInt ( byte * input , word32 * inOutIdx , word32 number , word32 maxIdx ) { word32 idx = * inOutIdx ; word32 len = 0 ; int i ; byte ar [ MAX_LENGTH_SZ ] ; if ( ( idx + 2 ) > maxIdx ) return BUFFER_E ; input [ idx ++ ] = ASN_INTEGER ; idx ++ ; if ( MAX_LENGTH_SZ + idx > maxIdx ) return ASN_PARSE_E ; XMEMSET ( ar , 0 , MAX_LENGTH_SZ ) ; c32toa ( number , ar ) ; for ( i = 0 ; i < MAX_LENGTH_SZ ; i ++ ) { if ( ar [ i ] != 0 ) { break ; } } if ( i == MAX_LENGTH_SZ ) { input [ idx ++ ] = 0 ; len ++ ; } for ( ; i < MAX_LENGTH_SZ && idx < maxIdx ; i ++ ) { input [ idx ++ ] = ar [ i ] ; len ++ ; } input [ * inOutIdx + 1 ] = ( byte ) len ; * inOutIdx = idx ; return len + 2 ; }
Set small integer, 32 bits or less.
Set small integer 32 bits or less .
/* check for room for type and length bytes */ /* place holder for length byte */ /* find first non zero byte */ /* handle case of 0 */ /* jump back to beginning of input buffer using unaltered inOutIdx value
     * and set number of bytes for integer, then update the index value */ /* size of integer bytes plus ASN TAG and length byte */