Пример #1
0
//------------------------------------------------------------------------------
/// Decrypts a variable-length cipher text
/// \param pCipherText text to decrypt
/// \param pPlainText to store plain text
/// \param length of cipher text (in bytes)
/// \return: 1 if ok, 0 if error
//------------------------------------------------------------------------------
int aes_hard_decrypt(const unsigned char *pCipherText,
                     unsigned char *pPlainText,
                     unsigned int length)
{
    TRACE_DEBUG("aes_hard_decrypt\n\r");

    // Check parameters
    if ((pCipherText == NULL) || (pPlainText == NULL)) {
        return 0;
    }

#ifdef AT91C_BASE_PDC_AES
    // Set source and destination buffers in PDC
    AT91C_BASE_PDC_AES->PDC_TPR = (unsigned int) pCipherText;
    AT91C_BASE_PDC_AES->PDC_RPR = (unsigned int) pPlainText;

    AT91C_BASE_PDC_AES->PDC_TCR = length >> 2;
    AT91C_BASE_PDC_AES->PDC_RCR = length >> 2;

    // Start decryption and wait
    AT91C_BASE_PDC_AES->PDC_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN;
    while (((AES_GetStatus()) & AT91C_AES_ENDRX) == 0);
#else

    // Enable DMA chanels
    AT91C_BASE_HDMA->HDMA_CHER = (1<<0) | (1<<1);
    // Wait end of transfer
    while( (AT91C_BASE_HDMA->HDMA_CHSR & ((1<<0)|(1<<1))) != 0 );
#endif

    return 1;
}
Пример #2
0
//------------------------------------------------------------------------------
/// Decrypts a variable-length cipher text
/// \param pCipherText text to decrypt
/// \param pPlainText to store plain text
/// \param length of cipher text (in bytes)
/// \return: 1 if ok, 0 if error
//------------------------------------------------------------------------------
int aes_hard_decrypt(const unsigned char *pCipherText,
                     unsigned char *pPlainText,
                     unsigned int length)
{
    TRACE_DEBUG("aes_hard_decrypt\n\r");

    // Check parameters
    if ((pCipherText == NULL) || (pPlainText == NULL)) {
        return 0;
    }

    // Set source and destination buffers in PDC
    AT91C_BASE_PDC_AES->PDC_TPR = (unsigned int) pCipherText;
    AT91C_BASE_PDC_AES->PDC_RPR = (unsigned int) pPlainText;

    AT91C_BASE_PDC_AES->PDC_TCR = length >> 2;
    AT91C_BASE_PDC_AES->PDC_RCR = length >> 2;

    // Start decryption and wait
    AT91C_BASE_PDC_AES->PDC_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN;
    while (((AES_GetStatus()) & AT91C_AES_ENDRX) == 0);

    return 1;
}