1*62c56f98SSadaf Ebrahimi /** Helper functions for tests that manipulate ASN.1 data. 2*62c56f98SSadaf Ebrahimi */ 3*62c56f98SSadaf Ebrahimi /* 4*62c56f98SSadaf Ebrahimi * Copyright The Mbed TLS Contributors 5*62c56f98SSadaf Ebrahimi * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 6*62c56f98SSadaf Ebrahimi */ 7*62c56f98SSadaf Ebrahimi 8*62c56f98SSadaf Ebrahimi #ifndef ASN1_HELPERS_H 9*62c56f98SSadaf Ebrahimi #define ASN1_HELPERS_H 10*62c56f98SSadaf Ebrahimi 11*62c56f98SSadaf Ebrahimi #include "test/helpers.h" 12*62c56f98SSadaf Ebrahimi 13*62c56f98SSadaf Ebrahimi /** Skip past an INTEGER in an ASN.1 buffer. 14*62c56f98SSadaf Ebrahimi * 15*62c56f98SSadaf Ebrahimi * Mark the current test case as failed in any of the following conditions: 16*62c56f98SSadaf Ebrahimi * - The buffer does not start with an ASN.1 INTEGER. 17*62c56f98SSadaf Ebrahimi * - The integer's size or parity does not match the constraints expressed 18*62c56f98SSadaf Ebrahimi * through \p min_bits, \p max_bits and \p must_be_odd. 19*62c56f98SSadaf Ebrahimi * 20*62c56f98SSadaf Ebrahimi * \param p Upon entry, `*p` points to the first byte of the 21*62c56f98SSadaf Ebrahimi * buffer to parse. 22*62c56f98SSadaf Ebrahimi * On successful return, `*p` points to the first byte 23*62c56f98SSadaf Ebrahimi * after the parsed INTEGER. 24*62c56f98SSadaf Ebrahimi * On failure, `*p` is unspecified. 25*62c56f98SSadaf Ebrahimi * \param end The end of the ASN.1 buffer. 26*62c56f98SSadaf Ebrahimi * \param min_bits Fail the test case if the integer does not have at 27*62c56f98SSadaf Ebrahimi * least this many significant bits. 28*62c56f98SSadaf Ebrahimi * \param max_bits Fail the test case if the integer has more than 29*62c56f98SSadaf Ebrahimi * this many significant bits. 30*62c56f98SSadaf Ebrahimi * \param must_be_odd Fail the test case if the integer is even. 31*62c56f98SSadaf Ebrahimi * 32*62c56f98SSadaf Ebrahimi * \return \c 0 if the test failed, otherwise 1. 33*62c56f98SSadaf Ebrahimi */ 34*62c56f98SSadaf Ebrahimi int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end, 35*62c56f98SSadaf Ebrahimi size_t min_bits, size_t max_bits, 36*62c56f98SSadaf Ebrahimi int must_be_odd); 37*62c56f98SSadaf Ebrahimi 38*62c56f98SSadaf Ebrahimi #endif /* ASN1_HELPERS_H */ 39