CryptoLib icon indicating copy to clipboard operation
CryptoLib copied to clipboard

static int32_t sadb_sa_setARSN(void)

Open Peco602 opened this issue 4 years ago • 2 comments

This function should set the Anti-Replay Counter, but it sets the Initialization Vector.

Peco602 avatar Jan 04 '22 13:01 Peco602

/**
 * @brief Function: sadb_sa_setASRN
 * @return int32: Success/Failure
 **/
static int32_t sadb_sa_setARSN(void)
{
    // Local variables
    uint16_t spi = 0x0000;
    int x;

    // Read ingest
    spi = ((uint8_t)sdls_frame.pdu.data[0] << 8) | (uint8_t)sdls_frame.pdu.data[1];
    printf("spi = %d \n", spi);

    // TODO: Check SA type (authenticated, encrypted, both) and set appropriately
    // TODO: Add more checks on bounds

    // Check SPI exists
    if (spi < NUM_SA)
    {
#ifdef PDU_DEBUG
        printf("SPI %d IV updated to: 0x", spi);
#endif
        if (sa[spi].shivf_len > 0)
        { // Set IV - authenticated encryption
            for (x = 0; x < IV_SIZE; x++)
            {
                *(sa[spi].iv + x) = (uint8_t)sdls_frame.pdu.data[x + 2];
#ifdef PDU_DEBUG
                printf("%02x", *(sa[spi].iv + x));
#endif
            }
            Crypto_increment(sa[spi].iv, sa[spi].shivf_len);
        }
        else
        { // Set SN
          // TODO
        }
#ifdef PDU_DEBUG
        printf("\n");
#endif
    }
    else
    {
        printf("sadb_sa_setARSN ERROR: SPI %d does not exist.\n", spi);
    }

    return CRYPTO_LIB_SUCCESS;
}

rjbrown2 avatar Oct 18 '23 16:10 rjbrown2

This is valid. The shivf and iv variables should all be changed to shsnf and arsn, and then validated.

rjbrown2 avatar Oct 18 '23 16:10 rjbrown2