mbed/COMPONENT_AWSIOT_PKCS11PSA/corePKCS11/core_pki_utils.c
/*
 * An ASN.1 encoded signature is a sequence of two ASN.1 integers. Parse one of
 * those integers and convert it to the fixed-length encoding expected by PSA.
 */
An ASN.1 encoded signature is a sequence of two ASN.1 integers. Parse one of
those integers and convert it to the fixed-length encoding expected by PSA.
An ASN . 1 encoded signature is a sequence of two ASN . 1 integers . Parse one of those integers and convert it to the fixed - length encoding expected by PSA .
static int extract_ecdsa_sig_int( unsigned char **from, const unsigned char *end,
                                  unsigned char *to, size_t to_len )
{
    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
    size_t unpadded_len, padding_len;
    if( ( ret = mbedtls_asn1_get_tag( from, end, &unpadded_len,
                                      MBEDTLS_ASN1_INTEGER ) ) != 0 )
    {
        return( ret );
    }
    while( unpadded_len > 0 && **from == 0x00 )
    {
        ( *from )++;
        unpadded_len--;
    }
    if( unpadded_len > to_len || unpadded_len == 0 )
        return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
    padding_len = to_len - unpadded_len;
    memset( to, 0x00, padding_len );
    memcpy( to + padding_len, *from, unpadded_len );
    ( *from ) += unpadded_len;
    return( 0 );
}
static int extract_ecdsa_sig_int ( unsigned char * * from , const unsigned char * end , unsigned char * to , size_t to_len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED ; size_t unpadded_len , padding_len ; if ( ( ret = mbedtls_asn1_get_tag ( from , end , & unpadded_len , MBEDTLS_ASN1_INTEGER ) ) != 0 ) { return ( ret ) ; } while ( unpadded_len > 0 && * * from == 0x00 ) { ( * from ) ++ ; unpadded_len -- ; } if ( unpadded_len > to_len || unpadded_len == 0 ) return ( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ; padding_len = to_len - unpadded_len ; memset ( to , 0x00 , padding_len ) ; memcpy ( to + padding_len , * from , unpadded_len ) ; ( * from ) += unpadded_len ; return ( 0 ) ; }
An ASN.1 encoded signature is a sequence of two ASN.1 integers.
An ASN . 1 encoded signature is a sequence of two ASN . 1 integers .